From 3db4deb692b8e9c05c7f4803aae260cad3285b45 Mon Sep 17 00:00:00 2001 From: Sergey Matvienko Date: Sun, 18 Oct 2026 14:34:41 +0200 Subject: [PATCH] Fixed flaky HttpIntegrationTest integration start wait HttpIntegrationTest creates the integration disabled and enables it right away, which produces CREATED and UPDATED lifecycle messages. The CREATED task reads the integration configuration when it runs. If the enable has already been committed, that task starts the integration (STARTED), and the UPDATED task that follows calls update() on the running integration and persists an UPDATED event. waitUntilIntegrationStarted required the latest lifecycle event to be STARTED, so it timed out after 30 s even though the integration was up. Accept a successful STARTED or UPDATED as the latest lifecycle event. --- .../integration/AbstractIntegrationTest.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/application/src/test/java/org/thingsboard/server/service/integration/AbstractIntegrationTest.java b/application/src/test/java/org/thingsboard/server/service/integration/AbstractIntegrationTest.java index 2d72b6b6db..4164eb4eb2 100644 --- a/application/src/test/java/org/thingsboard/server/service/integration/AbstractIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/service/integration/AbstractIntegrationTest.java @@ -164,6 +164,14 @@ public abstract class AbstractIntegrationTest extends AbstractControllerTest { return targetMsgs; } + /** + * Waits until the latest lifecycle event says the integration is running. + *

+ * An integration that is created disabled and then enabled right away gets two lifecycle messages, CREATED and UPDATED. + * The CREATED task reads the configuration when it runs. If the enable is already committed by then, that task + * starts the integration and persists STARTED, and the UPDATED task that follows persists UPDATED on the running + * integration. So the latest event can be either STARTED or UPDATED, and both mean the integration is up. + */ protected void waitUntilIntegrationStarted(TenantId tenantId, IntegrationId integrationId) { Awaitility .await() @@ -176,8 +184,11 @@ public abstract class AbstractIntegrationTest extends AbstractControllerTest { } EventInfo event = events.getData().stream().max(Comparator.comparingLong(EventInfo::getCreatedTime)).orElse(null); - return event != null - && "STARTED".equals(event.getBody().get("event").asText()) + if (event == null) { + return false; + } + String eventType = event.getBody().get("event").asText(); + return ("STARTED".equals(eventType) || "UPDATED".equals(eventType)) && "true".equals(event.getBody().get("success").asText()); }); }