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 +4 -4
- data/lib/rspec/openhab/timer.rb +2 -0
- data/lib/rspec/openhab/version.rb +1 -1
- data/lib/rspec/openhab/wait.rb +66 -5
- data/lib/rspec-openhab-scripting.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b4f4a385d3672410faee3ca6a90eb931f4499060de30d5dfc11869c73b78db7
|
4
|
+
data.tar.gz: 2d6c73ceabd6796134434250824ee255f80cc74b98b16f4172ac76d6be350c5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9153da220c8491f9a8f79bed277646df27b95ed4c17fb0181dcfd8519df0d9443c989ace2f2fe8da3fb39c14e177d7147e7148cffd5a47baa6a121a821ce883
|
7
|
+
data.tar.gz: 70b3fefd8b2df95db3fc553fcb785c48c8e63d3671c0922328bd0937819e7f3b3cc164edb58e3d4fc04da20101297c65868696ebf624b664892b16c86bed22cd
|
data/lib/rspec/openhab/timer.rb
CHANGED
data/lib/rspec/openhab/wait.rb
CHANGED
@@ -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
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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.
|
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-
|
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
|