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.
This commit is contained in:
Niels Kootstra authored and GitHub committed 2026-10-02 14:51:34 -04:00
1 parent 1d85e6bf6e
commit 02b0a3f536
1 file changed
+12 -31
@@ -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 {