rspec-openhab-scripting 0.0.7-java → 0.0.8-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76dfb6fa24e9d5efd4f0857cde57ae0c299f7ff5b6c16d08981fe04aa5ab3f52
4
- data.tar.gz: b587bf33488da0f9a095eba35997ae4e615b6f8729ed11e1f8c514d1a195e7e1
3
+ metadata.gz: 5b4f4a385d3672410faee3ca6a90eb931f4499060de30d5dfc11869c73b78db7
4
+ data.tar.gz: 2d6c73ceabd6796134434250824ee255f80cc74b98b16f4172ac76d6be350c5b
5
5
  SHA512:
6
- metadata.gz: 80961c7142353a5cd237414ed8a854a1ce33ef4fe0a32c758bf3a41921e6a3cf92e811fc635b9c72cc5e2d59cf1eb92710ad0a8cbb6cf6a357400180e8c4ba56
7
- data.tar.gz: a3cef22e84c40c6f9780830873a0ac1c548e7076c81df9afe9d8fbe9e9bb30e9c316dc6352d329e1c7d95c0be470ebb319f2a7d2c3668c9b8462b24e7e45ebca
6
+ metadata.gz: e9153da220c8491f9a8f79bed277646df27b95ed4c17fb0181dcfd8519df0d9443c989ace2f2fe8da3fb39c14e177d7147e7148cffd5a47baa6a121a821ce883
7
+ data.tar.gz: 70b3fefd8b2df95db3fc553fcb785c48c8e63d3671c0922328bd0937819e7f3b3cc164edb58e3d4fc04da20101297c65868696ebf624b664892b16c86bed22cd
@@ -3,8 +3,10 @@
3
3
  RSpec.configure do |config|
4
4
  config.before(:each) do
5
5
  OpenHAB::DSL::Timers.timer_manager.cancel_all
6
+ wait_for_background_tasks
6
7
  end
7
8
  config.after(:each) do
8
9
  OpenHAB::DSL::Timers.timer_manager.cancel_all
10
+ wait_for_background_tasks
9
11
  end
10
12
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module OpenHAB
5
- VERSION = "0.0.7"
5
+ VERSION = "0.0.8"
6
6
  end
7
7
  end
@@ -4,14 +4,75 @@ module RSpec
4
4
  module OpenHAB
5
5
  module Wait
6
6
  def wait_for_rules
7
+ wait_for_background_tasks(timers: false)
8
+ end
9
+
10
+ def wait_for_timers
11
+ wait_for_background_tasks(rules: false)
12
+ end
13
+
14
+ def wait_for_background_tasks(rules: true, timers: true)
7
15
  loop do
8
- sleep(0.1)
9
- break if java.lang.Thread.all_stack_traces.keys.all? do |t|
10
- !t.name.match?(/^OH-rule-/) ||
11
- [java.lang.Thread::State::WAITING, java.lang.Thread::State::TIMED_WAITING].include?(t.state)
12
- end
16
+ sleep 0.1
17
+ next if java.lang.Thread.all_stack_traces.any? do |(t, stack)|
18
+ # this is just an estimate. I see 9 when it's parked waiting
19
+ # for an event, but once it hits ruby it gets real big real quick
20
+ min_frames = 15
21
+
22
+ case t.name
23
+ when /^OH-scheduler-/
24
+ # timer thread; born and die for each timer
25
+ if thread_running?(t) || stack.length > min_frames
26
+ logger.debug "thread #{t.name} is running (#{stack.length})"
27
+ stack.each do |frame|
28
+ logger.trace " #{frame}"
29
+ end
30
+ next timers
31
+ end
32
+ when /^OH-rule-/
33
+
34
+ if thread_running?(t) || stack.length > min_frames
35
+ logger.debug "thread #{t.name} is running (#{stack.length})"
36
+ stack.each do |frame|
37
+ logger.trace " #{frame}"
38
+ end
39
+
40
+ next rules
41
+ end
42
+ when /^OH-(?:eventwatcher|eventexecutor)-/
43
+ # an event is making its way through the system
44
+ if thread_running?(t)
45
+ logger.debug "thread #{t.name} is running"
46
+ next rules
47
+ end
48
+ end
49
+ end
50
+
51
+ # no need to retry if there were no timers
52
+ break unless timers && wait_for_next_timer
13
53
  end
14
54
  end
55
+
56
+ private
57
+
58
+ def thread_running?(thread)
59
+ ![java.lang.Thread::State::WAITING,
60
+ java.lang.Thread::State::TIMED_WAITING].include?(thread.state)
61
+ end
62
+
63
+ def wait_for_next_timer
64
+ latest = ::OpenHAB::DSL::Timers.timer_manager.instance_variable_get(:@timers).min_by(&:execution_time)
65
+ return false unless latest
66
+
67
+ delta = (latest.execution_time.to_instant.to_epoch_milli - java.time.Instant.now.to_epoch_milli) / 1000.0
68
+ # in the past? it's probably executing
69
+ return true if delta.negative?
70
+
71
+ logger.info("Waiting #{delta}s for next timer") if delta > 5
72
+
73
+ sleep(delta)
74
+ true
75
+ end
15
76
  end
16
77
  end
17
78
  end
@@ -70,10 +70,11 @@ require "rspec/openhab/core/cron_scheduler"
70
70
  # RSpec additions
71
71
  require "rspec/core"
72
72
  require "rspec/openhab/dsl/rules/rspec"
73
+ require "rspec/openhab/items"
73
74
  require "rspec/openhab/state"
75
+ require "rspec/openhab/timer"
74
76
  require "rspec/openhab/trigger"
75
77
  require "rspec/openhab/wait"
76
- require "rspec/openhab/items"
77
78
 
78
79
  RSpec::OpenHAB::Items.populate_items_from_api(api)
79
80
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: java
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-01 00:00:00.000000000 Z
11
+ date: 2022-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement