Skip to content

Commit 35aa934

Browse files
committed
Fix test timing issue
1 parent 95c3a79 commit 35aa934

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

server-common/src/test/java/io/a2a/server/requesthandlers/DefaultRequestHandlerTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,23 @@ void testBlockingCallReturnsCompleteTaskWithArtifacts() throws Exception {
809809
assertTrue(result instanceof Task, "Result should be a Task");
810810
Task returnedTask = (Task) result;
811811

812-
// Verify task is completed
812+
// Verify task is completed - poll with retry to handle race condition
813+
// where MainEventBusProcessor may not have finished updating TaskStore yet
814+
// (especially on Java 21 with different thread scheduling)
815+
long pollStart = System.currentTimeMillis();
816+
long pollTimeoutMs = 1000; // 1 second max
817+
while (returnedTask.getStatus().state() != TaskState.COMPLETED
818+
&& (System.currentTimeMillis() - pollStart) < pollTimeoutMs) {
819+
try {
820+
Thread.sleep(10);
821+
// Fetch latest state from TaskStore
822+
returnedTask = taskStore.get(taskId);
823+
} catch (InterruptedException e) {
824+
Thread.currentThread().interrupt();
825+
break;
826+
}
827+
}
828+
813829
assertEquals(TaskState.COMPLETED, returnedTask.getStatus().state(),
814830
"Returned task should be COMPLETED");
815831

0 commit comments

Comments
 (0)