From 456c78eea182a120e225ab6756916891ae3dddfb Mon Sep 17 00:00:00 2001 From: Blake Li Date: Fri, 13 Nov 2026 21:16:56 +0000 Subject: [PATCH] test(pubsub): deflake SubscriberTest.testStreamAckDeadlineIsSetCorrectly 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 --- .../java/com/google/cloud/pubsub/v1/SubscriberTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/java-pubsub/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java b/java-pubsub/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java index 649769d1c671..04ed05c45e08 100644 --- a/java-pubsub/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java +++ b/java-pubsub/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java @@ -250,6 +250,10 @@ public void testStreamAckDeadlineIsSetCorrectly() throws Exception { fakeSubscriberServiceImpl.getLastSeenRequest().getStreamAckDeadlineSeconds()); subscriber.stopAsync().awaitTerminated(); + // awaitTerminated() only covers the client side. The fake server finds out asynchronously + // that the stream was closed, so wait for that before starting the next subscriber. Otherwise + // the old stream may still be counted, and its request returned, by the assertions below. + fakeSubscriberServiceImpl.waitForClosedStreams(1); // Deadline is higher than the allowed streamAckDeadline. maxDurationPerAckExtension = 700; @@ -265,6 +269,7 @@ public void testStreamAckDeadlineIsSetCorrectly() throws Exception { fakeSubscriberServiceImpl.getLastSeenRequest().getStreamAckDeadlineSeconds()); subscriber.stopAsync().awaitTerminated(); + fakeSubscriberServiceImpl.waitForClosedStreams(2); // Deadline is within the allowed limits for streamAckDeadline. maxDurationPerAckExtension = 100; @@ -280,6 +285,7 @@ public void testStreamAckDeadlineIsSetCorrectly() throws Exception { fakeSubscriberServiceImpl.getLastSeenRequest().getStreamAckDeadlineSeconds()); subscriber.stopAsync().awaitTerminated(); + fakeSubscriberServiceImpl.waitForClosedStreams(3); // maxDurationPerAckExtension is unset. subscriber = startSubscriber(getTestSubscriberBuilder(testReceiver));