Skip to content

Commit 3dfa2bf

Browse files
authored
fix: Eliminate race condition in testInputRequiredWorkflow (#630)
The test consumers were counting down their latches on the FIRST TaskEvent received, which could be the intermediate WORKING state instead of the expected terminal state (INPUT_REQUIRED or COMPLETED). This caused intermittent test failures with: expected: <INPUT_REQUIRED> but was: <WORKING> Fix: Both consumers now only count down when receiving the expected terminal state: - initialConsumer waits for INPUT_REQUIRED (not WORKING) - completionConsumer waits for COMPLETED (not WORKING) This matches the agent's event emission pattern: agentEmitter.startWork() // WORKING state agentEmitter.requiresInput(...) // INPUT_REQUIRED state ...later... agentEmitter.startWork() // WORKING state agentEmitter.complete() // COMPLETED state
1 parent 29bd6bb commit 3dfa2bf

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,9 +1512,17 @@ public void testInputRequiredWorkflow() throws Exception {
15121512
AtomicBoolean initialUnexpectedEvent = new AtomicBoolean(false);
15131513

15141514
BiConsumer<ClientEvent, AgentCard> initialConsumer = (event, agentCard) -> {
1515+
// Idempotency guard: prevent late events from modifying state after latch countdown
1516+
if (initialLatch.getCount() == 0) {
1517+
return;
1518+
}
15151519
if (event instanceof TaskEvent te) {
1516-
initialState.set(te.getTask().status().state());
1517-
initialLatch.countDown();
1520+
TaskState state = te.getTask().status().state();
1521+
initialState.set(state);
1522+
// Only count down when we receive INPUT_REQUIRED, not intermediate states like WORKING
1523+
if (state == TaskState.INPUT_REQUIRED) {
1524+
initialLatch.countDown();
1525+
}
15181526
} else {
15191527
initialUnexpectedEvent.set(true);
15201528
}
@@ -1538,9 +1546,17 @@ public void testInputRequiredWorkflow() throws Exception {
15381546
AtomicBoolean completionUnexpectedEvent = new AtomicBoolean(false);
15391547

15401548
BiConsumer<ClientEvent, AgentCard> completionConsumer = (event, agentCard) -> {
1549+
// Idempotency guard: prevent late events from modifying state after latch countdown
1550+
if (completionLatch.getCount() == 0) {
1551+
return;
1552+
}
15411553
if (event instanceof TaskEvent te) {
1542-
completedState.set(te.getTask().status().state());
1543-
completionLatch.countDown();
1554+
TaskState state = te.getTask().status().state();
1555+
completedState.set(state);
1556+
// Only count down when we receive COMPLETED, not intermediate states like WORKING
1557+
if (state == TaskState.COMPLETED) {
1558+
completionLatch.countDown();
1559+
}
15441560
} else {
15451561
completionUnexpectedEvent.set(true);
15461562
}

0 commit comments

Comments
 (0)