Class: RspecTimeGuard::TimeoutMonitor
- Inherits:
-
Object
- Object
- RspecTimeGuard::TimeoutMonitor
- Defined in:
- lib/rspec_time_guard.rb
Instance Method Summary collapse
-
#initialize ⇒ TimeoutMonitor
constructor
A new instance of TimeoutMonitor.
- #register_test(example, timeout, thread) ⇒ Object
- #unregister_test(example) ⇒ Object
Constructor Details
#initialize ⇒ TimeoutMonitor
Returns a new instance of TimeoutMonitor.
11 12 13 14 15 |
# File 'lib/rspec_time_guard.rb', line 11 def initialize @active_tests = {} @mutex = Mutex.new @monitor_thread = nil end |
Instance Method Details
#register_test(example, timeout, thread) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rspec_time_guard.rb', line 17 def register_test(example, timeout, thread) @mutex.synchronize do @active_tests[example.object_id] = { example: example, start_time: Time.now, timeout: timeout, thread_id: thread.object_id, warned: false } # NOTE: We start monitor thread if not already running start_monitor_thread if @monitor_thread.nil? || !@monitor_thread.alive? end end |
#unregister_test(example) ⇒ Object
32 33 34 35 36 |
# File 'lib/rspec_time_guard.rb', line 32 def unregister_test(example) @mutex.synchronize do @active_tests.delete(example.object_id) end end |