Skip to content

test(pubsub): deflake SubscriberTest.testStreamAckDeadlineIsSetCorrectly - #15005

Open
blakeli0 wants to merge 1 commit into
googleapis:mainfrom
blakeli0:test/pubsub-deflake-stream-ack-deadline-test
Open

blakeli0 wants to merge 1 commit into
googleapis:mainfrom
blakeli0:test/pubsub-deflake-stream-ack-deadline-test

Conversation

@blakeli0

Copy link
Copy Markdown
Contributor

SubscriberTest.testStreamAckDeadlineIsSetCorrectly starts and stops four subscribers in a row against one FakeSubscriberServiceImpl, and it is flaky.

subscriber.stopAsync().awaitTerminated() only waits for the client side. The fake removes a stream from its list of opened streams later, when its server thread sees the client's cancellation. If the next subscriber starts before that happens, the fake is still tracking the previous stream and the test fails in one of two ways:

  • expected:<1> but was:<2>: the old and the new stream are both counted as open.
  • A stale stream ack deadline such as expected:<600> but was:<10>: only the old stream is listed so far, so getLastSeenRequest() returns the previous subscriber's request.

This change waits for the fake to record each closed stream (waitForClosedStreams) before starting the next subscriber. It only touches the test.

Verification

Run locally on JDK 25:

Test as on main With this change
6,000 runs of the test method 17 failures, with both signatures above 0 failures
5 runs with a 200 ms delay temporarily added to the fake's close handling (local experiment, not in this PR) 5 failures 0 failures

SubscriberTest passes (13 tests) and fmt-maven-plugin:check is clean for google-cloud-pubsub.

The failure was seen in ci / split-units (java-pubsub, 8): https://github.com/googleapis/google-cloud-java/actions/runs/41130804887/job/124321665889. The stale-deadline variant was reported for this test in googleapis/java-pubsub#682.

b/580634974

The test starts and stops four subscribers in a row against one fake
server. awaitTerminated() only waits for the client side; the fake removes
a stream from its list of opened streams later, when it sees the client's
cancellation. If the next subscriber started first, the fake was still
tracking the previous stream and the test failed with either
"expected:<1> but was:<2>" (opened-stream count) or a stale stream ack
deadline such as "expected:<600> but was:<10>".

Wait for the fake server to record each closed stream before starting the
next subscriber.

b/580634974
@blakeli0
blakeli0 requested review from a team as code owners November 13, 2026 21:17

@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 SubscriberTest.java by adding calls to fakeSubscriberServiceImpl.waitForClosedStreams() after terminating the subscriber. This ensures that the fake server asynchronously registers that the stream was closed before proceeding, preventing assertions from incorrectly counting old streams. I have no feedback to provide as there are no review comments.

This branch has not been deployed

No deployments
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.

1 participant