Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Fixed timing issues with stopped time

Michal Rutkaba16ccfc7b99
diff --git a/agent/src/test/groovy/org/openremote/test/rules/ClimateControlTest.groovy b/agent/src/test/groovy/org/openremote/test/rules/ClimateControlTest.groovy
index 0eb346864..99f570fc2 100644
--- a/agent/src/test/groovy/org/openremote/test/rules/ClimateControlTest.groovy
+++ b/agent/src/test/groovy/org/openremote/test/rules/ClimateControlTest.groovy
@@ -7,35 +7,13 @@ import org.openremote.agent.AgentService
import org.openremote.agent.rules.RulesProvider
import org.openremote.test.ContainerTrait
import spock.lang.Specification
+import spock.lang.Unroll
import spock.util.concurrent.BlockingVariable
import spock.util.concurrent.PollingConditions
import spock.lang.Ignore
import java.util.stream.Stream
-@Ignore
-/*
-TODO Failing sometimes, still something time sensitive in here:
-
-Condition not satisfied after 10.00 seconds and 96 attempts
- at spock.util.concurrent.PollingConditions.within(PollingConditions.java:164)
- at spock.util.concurrent.PollingConditions.eventually(PollingConditions.java:134)
- at org.openremote.test.rules.ClimateControlTest.Person sense test(ClimateControlTest.groovy:259)
-Caused by: Condition not satisfied:
-
-sensor("VPERSONSENSETIME") == "16:00:00"
-| |
-10:15:00 false
- 3 differences (62% similarity)
- 1(0):(15):00
- 1(6):(00):00
-
- at org.openremote.test.rules.ClimateControlTest.Person sense test_closure14(ClimateControlTest.groovy:261)
- at org.openremote.test.rules.ClimateControlTest.Person sense test_closure14(ClimateControlTest.groovy)
- at groovy.lang.Closure.call(Closure.java:423)
- at spock.util.concurrent.PollingConditions.within(PollingConditions.java:158)
- ... 2 more
- */
class ClimateControlTest extends Specification implements ContainerTrait {
def "Climate control basic test template"() {
@@ -178,6 +156,7 @@ class ClimateControlTest extends Specification implements ContainerTrait {
stopContainer(container)
}
+ @Unroll("test repeated #i time")
def "Person sense test"() {
given: "a deployment with commands and sensors"
@@ -220,6 +199,9 @@ class ClimateControlTest extends Specification implements ContainerTrait {
when: "Set time before going to office"
def conditions = new PollingConditions(timeout: 10, initialDelay: 0.25)
+ def dow = sensor("TimerEEE")
+ command "VETA.$dow", "09:00"
+ command "VETD.$dow", "17:00"
then: "Check if there is no person"
conditions.eventually {
@@ -229,6 +211,8 @@ class ClimateControlTest extends Specification implements ContainerTrait {
assert sensor("VPRESENCE") == "No"
assert sensor("VHEATING") == "ECO"
assert Double.parseDouble(sensor("VHEATINGSETPOINT")) == 16
+ assert sensor("VETA.$dow") == "09:00"
+ assert sensor("VETD.$dow") == "17:00"
}
when: "now let's enter the office at 10 AM"
@@ -252,14 +236,23 @@ class ClimateControlTest extends Specification implements ContainerTrait {
testCommandBuilder.incDroolsClock()
assert sensor("VNEXTACTION") == "Departure"
assert sensor("VATA") == "10:00"
- assert sensor("VPERSONSENSE") == "0"
assert sensor("VPRESENCE") == "Yes"
assert sensor("VHEATING") == "Comfort"
assert sensor("VR1.TEMPERATURE") == "20.0°"
- assert sensor("FS.PIR") == "off"
assert Double.parseDouble(sensor("VHEATINGSETPOINT")) == 20
}
+ when: "wait 5 sec"
+ time "10:00:05"
+ conditions = new PollingConditions(timeout: 10, initialDelay: 0.25)
+
+ then: "assure that PIR is idle"
+ conditions.eventually {
+ testCommandBuilder.incDroolsClock()
+ assert sensor("VPERSONSENSE") == "0"
+ assert sensor("FS.PIR") == "off"
+ }
+
when: "Advance time 15m"
time "10:15"
conditions = new PollingConditions(timeout: 10, initialDelay: 0.25)
@@ -305,13 +298,15 @@ class ClimateControlTest extends Specification implements ContainerTrait {
then: "see if times schifted by half an hour"
conditions.eventually {
- def dow = sensor("TimerEEE")
assert sensor("VETA.$dow") == "09:30"
assert sensor("VETD.$dow") == "16:30"
}
cleanup: "the server should be stopped"
stopContainer(container)
+
+ where:
+ i << (1..1)
}
}
\ No newline at end of file
diff --git a/agent/src/test/resources/org/openremote/test/rules/climatecontrol/ClimateControl.drl b/agent/src/test/resources/org/openremote/test/rules/climatecontrol/ClimateControl.drl
index a152b82ba..bd259311d 100644
--- a/agent/src/test/resources/org/openremote/test/rules/climatecontrol/ClimateControl.drl
+++ b/agent/src/test/resources/org/openremote/test/rules/climatecontrol/ClimateControl.drl
@@ -392,7 +392,7 @@ end
rule "PSB: decrease vacation counter at midnight"
when
$timer: SensorState(sensorName=="TimerHH", value!="N/A", eval(value.toString().substring(0,5).equals("00:00"))) // more reliable than timer(cron: )
- SensorState(sensorName=="VACATION", $v: value, eval(Integer.parseInt(value.toString())>0), this before $timer)
+ SensorState(sensorName=="VACATION", $v: value, eval(Integer.parseInt(value.toString())>0), this before [2m] $timer)
then
commands.execute("VACATION", Integer.parseInt($v.toString())-1);
end
@@ -524,8 +524,8 @@ rule "PSB: adjust estimated times at midnight"
when
SensorState(sensorName=="TimerEEE", $e: value)
$timer: SensorState(sensorName=="TimerHH", value!="N/A", eval(value.toString().substring(0,5).equals("23:58"))) // more reliable than timer(cron: )
- SensorState(sensorName matches ("VETD."+$e), $ved:value, this before $timer) // Loop cut
- SensorState(sensorName matches ("VETA."+$e), $vea:value, this before $timer)
+ SensorState(sensorName matches ("VETD."+$e), $ved:value, this before [1m] $timer) // Loop cut
+ SensorState(sensorName matches ("VETA."+$e), $vea:value, this before [1m] $timer)
SensorState(sensorName=="VATD", $vd:value, value!="-")
SensorState(sensorName=="VATA", $va:value, value!="-")
SensorState(sensorName=="VACATION", eval(Integer.parseInt(value.toString())==0))
@@ -548,6 +548,14 @@ then
commands.execute("VPERSONSENSETIME", $h.toString());
end
+rule "--pir echo"
+when
+ SensorState(sensorName=="FS.PIR", $v:value)
+ SensorState(sensorName=="TimerHH", $h:value)
+then
+ LOG.info("PIR state "+$v.toString()+" @"+$h);
+end
+
rule "-PSB: person sense"
when
SensorState($s:sensorName=="FS.PIR", value=="on")
@@ -1047,7 +1055,7 @@ rule "--PSB: increase total score every 15m"
when
$timer: SensorState(sensorName=="TimerHH", value!="N/A", eval(Integer.parseInt(value.toString().substring(3,5)) % 15 == 0)) // more reliable than timer(cron: )
SensorState(sensorName=="VSCORE", $s: value)
- SensorState(sensorName=="VTOTALSCORE", $ts: value, this before $timer)
+ SensorState(sensorName=="VTOTALSCORE", $ts: value, this before [1m] $timer)
then
commands.execute("VTOTALSCORE", Integer.parseInt($ts.toString())+Integer.parseInt($s.toString()));
end
@@ -1055,7 +1063,7 @@ end
rule "PSB: reward"
when
$ts: SensorState(sensorName=="VTOTALSCORE", $s: value, eval(Integer.parseInt(value.toString()) >= 1000))
- SensorState(sensorName=="VLEVEL", $l: value, this before $ts)
+ SensorState(sensorName=="VLEVEL", $l: value, this before [1m] $ts)
then
Integer i = Integer.parseInt($s.toString());
commands.execute("VTOTALSCORE", i-1000); // Reset score