From 02b0a3f5368c002dfe54fefb3046a9a93e5bbf08 Mon Sep 17 00:00:00 2001 From: Niels Kootstra <545768+nkootstra@users.noreply.github.com> Date: Fri, 2 Oct 2026 20:51:34 +0200 Subject: [PATCH] test(ssm): wait on the command rollup instead of the invocation status (#4938) mixedDirectAndQueuedTargetsRemainInProgress waited for the direct invocation to turn Success and then read the command's CompletedCount. runDirectCommandAsync stores the invocation and only afterwards rolls the result up into the command, so the read could land in between and see 0. Await the CompletedCount itself, assert ErrorCount on the rolled-up command rather than the copy sendCommand returned, and make the remaining wait helpers fail on timeout instead of returning silently. --- .../SsmCommandServiceDirectExecutionTest.java | 43 ++++++------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/src/test/java/io/github/hectorvent/floci/services/ssm/SsmCommandServiceDirectExecutionTest.java b/src/test/java/io/github/hectorvent/floci/services/ssm/SsmCommandServiceDirectExecutionTest.java index 46ff862177..7e8c428014 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ssm/SsmCommandServiceDirectExecutionTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ssm/SsmCommandServiceDirectExecutionTest.java @@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -487,10 +488,10 @@ class SsmCommandServiceDirectExecutionTest { assertEquals("InProgress", command.getStatus()); assertEquals("In Progress", command.getStatusDetails()); - waitForInvocationStatus(service, command.getCommandId(), "i-container", "us-west-2", "Success"); - Command updatedCommand = service.listCommands(command.getCommandId(), null, "us-west-2").getFirst(); - assertEquals(1, updatedCommand.getCompletedCount()); - assertEquals(0, command.getErrorCount()); + // The invocation turns Success before the command rollup runs, so wait on the rollup itself. + await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> assertEquals(1, + service.listCommands(command.getCommandId(), null, "us-west-2").getFirst().getCompletedCount())); + assertEquals(0, service.listCommands(command.getCommandId(), null, "us-west-2").getFirst().getErrorCount()); assertEquals("Success", service.getCommandInvocation(command.getCommandId(), "i-container", "us-west-2").getStatus()); assertEquals("Pending", @@ -738,35 +739,15 @@ class SsmCommandServiceDirectExecutionTest { service.getCommandInvocation(command.getCommandId(), "i-container", "us-west-2").getStatus()); } - private static String waitForCommandStatus(SsmCommandService service, String commandId, String region) throws InterruptedException { - for (int i = 0; i < 250; i++) { - Command command = service.listCommands(commandId, null, region).getFirst(); - if (!"InProgress".equals(command.getStatus())) { - return command.getStatus(); - } - TimeUnit.MILLISECONDS.sleep(20); - } - return service.listCommands(commandId, null, region).getFirst().getStatus(); + private static String waitForCommandStatus(SsmCommandService service, String commandId, String region) { + return await().atMost(Duration.ofSeconds(5)).pollInterval(Duration.ofMillis(20)) + .until(() -> service.listCommands(commandId, null, region).getFirst().getStatus(), + status -> !"InProgress".equals(status)); } - private static void waitForInvocationStatus(SsmCommandService service, String commandId, String instanceId, String region, String status) throws InterruptedException { - for (int i = 0; i < 50; i++) { - if (status.equals(service.getCommandInvocation(commandId, instanceId, region).getStatus())) { - return; - } - TimeUnit.MILLISECONDS.sleep(20); - } - } - - private static int waitForMessageCount(SsmCommandService service, String instanceId) throws InterruptedException { - for (int i = 0; i < 50; i++) { - int messageCount = service.getMessages(instanceId, "request-id", 30).size(); - if (messageCount > 0) { - return messageCount; - } - TimeUnit.MILLISECONDS.sleep(20); - } - return 0; + private static int waitForMessageCount(SsmCommandService service, String instanceId) { + return await().atMost(Duration.ofSeconds(5)).pollInterval(Duration.ofMillis(20)) + .until(() -> service.getMessages(instanceId, "request-id", 30).size(), count -> count > 0); } private static final class InMemoryStorageFactory extends StorageFactory {