Skip to content

Commit b0a7124

Browse files
committed
fix: Eliminate race condition in testInputRequiredWorkflow
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 b0a7124

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,8 +1513,12 @@ public void testInputRequiredWorkflow() throws Exception {
15131513

15141514
BiConsumer<ClientEvent, AgentCard> initialConsumer = (event, agentCard) -> {
15151515
if (event instanceof TaskEvent te) {
1516-
initialState.set(te.getTask().status().state());
1517-
initialLatch.countDown();
1516+
TaskState state = te.getTask().status().state();
1517+
initialState.set(state);
1518+
// Only count down when we receive INPUT_REQUIRED, not intermediate states like WORKING
1519+
if (state == TaskState.INPUT_REQUIRED) {
1520+
initialLatch.countDown();
1521+
}
15181522
} else {
15191523
initialUnexpectedEvent.set(true);
15201524
}
@@ -1539,8 +1543,12 @@ public void testInputRequiredWorkflow() throws Exception {
15391543

15401544
BiConsumer<ClientEvent, AgentCard> completionConsumer = (event, agentCard) -> {
15411545
if (event instanceof TaskEvent te) {
1542-
completedState.set(te.getTask().status().state());
1543-
completionLatch.countDown();
1546+
TaskState state = te.getTask().status().state();
1547+
completedState.set(state);
1548+
// Only count down when we receive COMPLETED, not intermediate states like WORKING
1549+
if (state == TaskState.COMPLETED) {
1550+
completionLatch.countDown();
1551+
}
15441552
} else {
15451553
completionUnexpectedEvent.set(true);
15461554
}

0 commit comments

Comments
 (0)