diff --git a/application/src/test/java/org/thingsboard/server/cf/AlarmRulesTest.java b/application/src/test/java/org/thingsboard/server/cf/AlarmRulesTest.java index 3a1446fb46..e13872e46e 100644 --- a/application/src/test/java/org/thingsboard/server/cf/AlarmRulesTest.java +++ b/application/src/test/java/org/thingsboard/server/cf/AlarmRulesTest.java @@ -407,9 +407,9 @@ public class AlarmRulesTest extends AbstractControllerTest { Argument temperatureArgument = new Argument(); temperatureArgument.setRefEntityKey(new ReferencedEntityKey("temperature", ArgumentType.TS_LATEST, null)); temperatureArgument.setDefaultValue("0"); - Map arguments = new HashMap<>(Map.of( + Map arguments = Map.of( "temperature", temperatureArgument - )); + ); long staticDurationMs = 5000L; Map createRules = Map.of( @@ -419,9 +419,13 @@ public class AlarmRulesTest extends AbstractControllerTest { CalculatedField calculatedField = createAlarmCf(deviceId, "High Temperature Alarm", arguments, createRules, null); - // post telemetry to trigger condition, so that firstEventTs > 0 in AlarmRuleState + // post telemetry to trigger condition and wait for the static-phase eval to produce a debug event, + // which guarantees firstEventTs > 0 in AlarmRuleState before we trigger REINIT postTelemetry(deviceId, "{\"temperature\":50}"); - Thread.sleep(1000); + CalculatedFieldId cfId = calculatedField.getId(); + await().atMost(TIMEOUT, TimeUnit.SECONDS) + .until(() -> getDebugEvents(cfId, 1), + events -> !events.isEmpty() && !events.get(0).getId().equals(latestEventId)); // update CF: add attribute argument and switch duration from static to dynamic AlarmCalculatedFieldConfiguration configuration =