Module: RSpec::OpenHAB::Wait
- Defined in:
- lib/rspec/openhab/wait.rb
Instance Method Summary collapse
- #wait_for_background_tasks(rules: true, timers: true) ⇒ Object
- #wait_for_rules ⇒ Object
- #wait_for_timers ⇒ Object
Instance Method Details
#wait_for_background_tasks(rules: true, timers: true) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rspec/openhab/wait.rb', line 14 def wait_for_background_tasks(rules: true, timers: true) loop do sleep 0.1 next if java.lang.Thread.all_stack_traces.any? do |(t, stack)| # this is just an estimate. I see 9 when it's parked waiting # for an event, but once it hits ruby it gets real big real quick min_frames = 15 case t.name when /^OH-scheduler-/ # timer thread; born and die for each timer if thread_running?(t) || stack.length > min_frames logger.debug "thread #{t.name} is running (#{stack.length})" stack.each do |frame| logger.trace " #{frame}" end next timers end when /^OH-rule-/ if thread_running?(t) || stack.length > min_frames logger.debug "thread #{t.name} is running (#{stack.length})" stack.each do |frame| logger.trace " #{frame}" end next rules end when /^OH-(?:eventwatcher|eventexecutor)-/ # an event is making its way through the system if thread_running?(t) logger.debug "thread #{t.name} is running" next rules end end end # no need to retry if there were no timers break unless timers && wait_for_next_timer end end |
#wait_for_rules ⇒ Object
6 7 8 |
# File 'lib/rspec/openhab/wait.rb', line 6 def wait_for_rules wait_for_background_tasks(timers: false) end |
#wait_for_timers ⇒ Object
10 11 12 |
# File 'lib/rspec/openhab/wait.rb', line 10 def wait_for_timers wait_for_background_tasks(rules: false) end |