From 2d7a4f468a2d666f0afd58360189cde51d81aff9 Mon Sep 17 00:00:00 2001 From: Sergey Matvienko Date: Sun, 18 Oct 2026 14:54:16 +0200 Subject: [PATCH] Fixed flaky AssetControllerTest edge notification count tests The rule engine stats report runs on a schedule. On its first report for a tenant it creates a QUEUE_STATS entity, whose SaveEntityEvent becomes an ADDED sendNotificationMsgToEdge call. When that tick fell between Mockito.reset and verify, testFindTenantAssets and testFindAssetTypesByTenantId saw one extra invocation (179 vs 178, 4 vs 3). Count only entity ids that have an edge event type, which is the same filter DefaultTbClusterService applies before sending to an edge. --- .../server/controller/AbstractNotifyEntityTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/application/src/test/java/org/thingsboard/server/controller/AbstractNotifyEntityTest.java b/application/src/test/java/org/thingsboard/server/controller/AbstractNotifyEntityTest.java index 9421e33f54..9ca0ba2fd0 100644 --- a/application/src/test/java/org/thingsboard/server/controller/AbstractNotifyEntityTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/AbstractNotifyEntityTest.java @@ -360,8 +360,13 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { } private void testSendNotificationMsgToEdgeServiceTimeEntityEqAny(TenantId tenantId, ActionType actionType, int cntTime) { + // Count only entities that can be synced to edge. Background services may save non-edge entities for the + // tenant at any moment (e.g. QUEUE_STATS created by the periodic rule engine stats report), and their + // ADDED notifications have no edge event type, so they are dropped by TbClusterService anyway. + ArgumentMatcher matcherEdgeEntityId = argument -> argument != null + && EdgeUtils.getEdgeEventTypeByEntityType(argument.getEntityType()) != null; Mockito.verify(tbClusterService, times(cntTime)).sendNotificationMsgToEdge(Mockito.eq(tenantId), - Mockito.any(), Mockito.any(EntityId.class), Mockito.any(), Mockito.isNull(), + Mockito.any(), Mockito.argThat(matcherEdgeEntityId), Mockito.any(), Mockito.isNull(), Mockito.eq(EdgeUtils.getEdgeEventActionTypeByActionType(actionType)), Mockito.any()); }