Skip to content

Commit 5938c78

Browse files
authored
fix: fix flaky test testNonBlockingWithMultipleMessages (#576)
# Description fix flaky test testNonBlockingWithMultipleMessages Fixes #557 🦕
1 parent 56ac4be commit 5938c78

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

tests/server-common/src/test/java/io/a2a/server/apps/common/AbstractA2AServerTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,9 +1274,11 @@ public void testDeletePushNotificationConfigSetWithoutConfigId() throws Exceptio
12741274
@Test
12751275
@Timeout(value = 1, unit = TimeUnit.MINUTES)
12761276
public void testNonBlockingWithMultipleMessages() throws Exception {
1277+
String multiEventTaskId = "multi-event-test-" + java.util.UUID.randomUUID();
1278+
try {
12771279
// 1. Send first non-blocking message to create task in WORKING state
12781280
Message message1 = Message.builder(MESSAGE)
1279-
.taskId("multi-event-test")
1281+
.taskId(multiEventTaskId)
12801282
.contextId("test-context")
12811283
.parts(new TextPart("First request"))
12821284
.build();
@@ -1301,7 +1303,7 @@ public void testNonBlockingWithMultipleMessages() throws Exception {
13011303
assertTrue(firstTaskLatch.await(10, TimeUnit.SECONDS));
13021304
String taskId = taskIdRef.get();
13031305
assertNotNull(taskId);
1304-
assertEquals("multi-event-test", taskId);
1306+
assertEquals(multiEventTaskId, taskId);
13051307

13061308
// 2. Resubscribe to task (queue should still be open)
13071309
CountDownLatch resubEventLatch = new CountDownLatch(2); // artifact-2 + completion
@@ -1337,7 +1339,7 @@ public void testNonBlockingWithMultipleMessages() throws Exception {
13371339

13381340
// 3. Send second streaming message to same taskId
13391341
Message message2 = Message.builder(MESSAGE)
1340-
.taskId("multi-event-test") // Same taskId
1342+
.taskId(multiEventTaskId) // Same taskId
13411343
.contextId("test-context")
13421344
.parts(new TextPart("Second request"))
13431345
.build();
@@ -1411,6 +1413,9 @@ public void testNonBlockingWithMultipleMessages() throws Exception {
14111413
assertEquals("artifact-2", streamArtifact.artifact().artifactId());
14121414
assertEquals("Second message artifact",
14131415
((TextPart) streamArtifact.artifact().parts().get(0)).text());
1416+
} finally {
1417+
deleteTaskInTaskStore(multiEventTaskId);
1418+
}
14141419
}
14151420

14161421
@Test

tests/server-common/src/test/java/io/a2a/server/apps/common/AgentExecutorProducer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void execute(RequestContext context, EventQueue eventQueue) throws A2AErr
2727
String taskId = context.getTaskId();
2828

2929
// Special handling for multi-event test
30-
if ("multi-event-test".equals(taskId)) {
30+
if (taskId != null && taskId.startsWith("multi-event-test")) {
3131
// First call: context.getTask() == null (new task)
3232
if (context.getTask() == null) {
3333
updater.startWork();

0 commit comments

Comments
 (0)