Browse Source

test: replace Thread.sleep with await on debug event before REINIT

Guarantees firstEventTs > 0 in AlarmRuleState before saveCalculatedField triggers REINIT, so the test reliably exercises the buggy reeval path on slow CI; otherwise ruleState.isEmpty() may stay true and the alarm gets created via the fallback path even without the fix.
pull/15439/head
Oleksandra Matviienko 5 months ago
parent
commit
7131e4018d
  1. 12
      application/src/test/java/org/thingsboard/server/cf/AlarmRulesTest.java

12
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<String, Argument> arguments = new HashMap<>(Map.of(
Map<String, Argument> arguments = Map.of(
"temperature", temperatureArgument
));
);
long staticDurationMs = 5000L;
Map<AlarmSeverity, Condition> 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 =

Loading…
Cancel
Save