Skip to content

Commit

Permalink
[mqtt.ruuvigateway] Fix itests (related to timeout tests in CI)
Browse files Browse the repository at this point in the history
Signed-off-by: Sami Salonen <[email protected]>
  • Loading branch information
ssalonen committed Sep 29, 2022
1 parent da048e7 commit dcc3603
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;

import javax.measure.quantity.Acceleration;
import javax.measure.quantity.Dimensionless;
Expand Down Expand Up @@ -169,6 +170,20 @@ private Thing createRuuviThing(String brokerPrefix, String topic, @Nullable Inte
}

private void triggerTimeoutHandling(Thing ruuviThing) {
// Simulate some time passing, so that RuuviTagHandler.heartbeat() is called twice
// Two heartbeat calls happens to trigger timeout handling in handler, one is not enough.
// (this is really implementation detail of RuuviTagHandler, making this test slightly
// error prone to possible changes in RuuviTagHandler implementation)
//
// 0. Assume some data received already, RuuviTagHandler.receivedData is true
// 1. First heartbeat sets receivedData=false; no further action is taken yet
// 2. Second heartbeat acts on false receivedData, e.g. updating Thing Status
for (int i = 0; i < 2; i++) {
callInternalHeartbeat(ruuviThing);
}
}

private void callInternalHeartbeat(Thing ruuviThing) {
ThingHandler handler = ruuviThing.getHandler();
Objects.requireNonNull(handler);
assertInstanceOf(RuuviTagHandler.class, handler);
Expand Down Expand Up @@ -256,7 +271,10 @@ public void retrieveAllRuuviPrefixedTopics() throws Exception {

private void assertThingStatus(List<ThingStatusInfo> statusUpdates, int index, ThingStatus status,
@Nullable ThingStatusDetail detail, @Nullable String description) {
assertTrue(statusUpdates.size() > index, "assert " + statusUpdates.size() + " > " + index + " failed");
assertTrue(statusUpdates.size() > index,
String.format("Not enough status updates. Expected %d, but only had %d. Status updates received: %s",
index + 1, statusUpdates.size(),
statusUpdates.stream().map(ThingStatusInfo::getStatus).collect(Collectors.toList())));
assertEquals(status, statusUpdates.get(index).getStatus(), statusUpdates.get(index).toString());
assertEquals(detail, statusUpdates.get(index).getStatusDetail(), statusUpdates.get(index).toString());
assertEquals(description, statusUpdates.get(index).getDescription(), statusUpdates.get(index).toString());
Expand Down

0 comments on commit dcc3603

Please sign in to comment.