Skip to content

test(pubsub): fix test race and re-enable testRunShutdown_TimeoutExceeded - #14339

Open
michaelpri10 wants to merge 1 commit into
googleapis:mainfrom
michaelpri10:main
Open

test(pubsub): fix test race and re-enable testRunShutdown_TimeoutExceeded#14339
michaelpri10 wants to merge 1 commit into
googleapis:mainfrom
michaelpri10:main

Conversation

@michaelpri10

Copy link
Copy Markdown
Contributor

Re-enable StreamingSubscriberConnectionTest.testRunShutdown_TimeoutExceeded
and resolve the test race condition that caused builds to hang indefinitely.

  • Synchronize the test thread with the background stop thread by polling
    for Thread.State.TIMED_WAITING before advancing FakeClock. This
    guarantees startTime is recorded before time advances, eliminating
    the infinite wait loop in Waiter.tryWait().
  • Reduce test shutdown timeout from 2s to 500ms to reduce test latency
    by ~1.5s per run.
  • Add proper connection termination cleanup to client pinger and server
    monitor tests to prevent background callbacks leaking into other tests.
  • Remove unused org.junit.Ignore import.
  • Ran 100 iterations of this test to confirm it is not flaky.

Fixes #13706

@michaelpri10
michaelpri10 requested review from a team as code owners September 9, 2026 21:29

@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 re-enables and fixes the previously ignored testRunShutdown_TimeoutExceeded test in StreamingSubscriberConnectionTest.java by adjusting timeouts and implementing a polling loop to wait for the stop thread to enter the TIMED_WAITING state. Additionally, it adds connection cleanup (stopAsync and awaitTerminated) to several other tests. The review feedback correctly points out that calling awaitTerminated() without a timeout in these cleanup steps could cause the test suite to hang indefinitely if a connection fails to shut down, and suggests adding a 5-second timeout instead.

Comment on lines +198 to +204
long startPoll = System.currentTimeMillis();
while (t.getState() != Thread.State.TIMED_WAITING && t.isAlive()) {
if (System.currentTimeMillis() - startPoll > 5000) {
fail("Timed out waiting for stop thread to enter TIMED_WAITING");
}
Thread.sleep(10);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fyi, we have introduced awaitility for testing deps in the Java SDK. Might be easier to test for polling cases.

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.

[java-pubsub] Pubsub Test - StreamingSubscriberConnectionTest Hangs

2 participants