fix: add awaitChildQueueCountStable to subscribe tests to prevent race condition by jmesnil · Pull Request #903 · a2aproject/a2a-java · GitHub
Skip to content

fix: add awaitChildQueueCountStable to subscribe tests to prevent race condition - #903

Merged
ehsavoie merged 3 commits into
a2aproject:mainfrom
jmesnil:worktree-fix-flaky-subscribe-test
Jun 1, 2026
Merged

ehsavoie merged 3 commits into
a2aproject:mainfrom
jmesnil:worktree-fix-flaky-subscribe-test

Conversation

@jmesnil

@jmesnil jmesnil commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add awaitChildQueueCountStable() synchronization to testSubscribeExistingTaskSuccess and testSubscribeExistingTaskSuccessWithClientConsumers in AbstractA2AServerTest
  • awaitStreamingSubscription() only guarantees transport-level subscription (Flow.Subscriber.onSubscribe() called), but the EventConsumer polling loop starts asynchronously on a separate thread. Without waiting for the child queue to stabilize, events enqueued on the server can be lost if they fire before the consumer is ready to receive them
  • This race is more pronounced with the Vert.x HTTP client (async event-loop model), causing flaky 30s timeouts in CI — which then cascades via Maven -fae to ban downstream modules like quarkus-app-1/quarkus-app-2, failing MultiInstanceReplicationTest with a Docker build-context error
  • The same synchronization pattern is already used in testResubscriptionPreservesEventsFromBothStreams (line ~1739)

Test plan

  • CI passes on all Java versions (17, 21, 25)
  • QuarkusA2AJSONRPCVertxTest.testSubscribeExistingTaskSuccess no longer times out
  • MultiInstanceReplicationTest no longer fails due to cascading ban

🤖 Generated with Claude Code

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates AbstractA2AServerTest.java to ensure that the EventConsumer polling loop has started before enqueuing events in the testSubscribeExistingTaskSuccess and testSubscribeExistingTaskSuccessWithClientConsumers test cases. This is achieved by waiting for the child queue count to become stable. There are no review comments, and I have no feedback to provide.

@jmesnil
jmesnil requested review from kabir and removed request for kabir June 1, 2026 07:09
…be tests

The subscribe tests were flaky because events were enqueued on the server
before the EventConsumer polling loop had started. awaitStreamingSubscription()
only guarantees transport-level subscription, not consumer readiness.

The fix captures the child queue count before subscribing and waits for it
to increment, confirming the subscription's EventConsumer is actively polling.
This is more robust than awaitChildQueueCountStable with a fixed expected
count, since ensureQueueForTask creates a child queue that remains in the
count.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jmesnil
jmesnil force-pushed the worktree-fix-flaky-subscribe-test branch from 476c497 to ea61e0f Compare June 1, 2026 07:35
@jmesnil
jmesnil requested a review from kabir June 1, 2026 07:55
@kabir

kabir commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the test suite in AbstractA2AServerTest.java to ensure that the EventConsumer polling loop has started before enqueuing events, preventing potential race conditions. The reviewer pointed out that using waitForChildQueueCountToBe is inefficient and can lead to socket exhaustion due to client-side polling. They suggested replacing it with awaitChildQueueCountStable to offload polling to the server side and ensure stability.

jmesnil and others added 2 commits June 1, 2026 10:06
…ps/common/AbstractA2AServerTest.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ps/common/AbstractA2AServerTest.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@ehsavoie
ehsavoie merged commit c1257e7 into a2aproject:main Jun 1, 2026
11 of 12 checks passed
@ehsavoie

ehsavoie commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants