Skip to content

Commit b7ba60b

Browse files
committed
pubsub: fix testModifyAckDeadline flaking, maybe
Previously MessageDispatcher starts off with deadline duration of 0. Since we need to extend deadline before the time is up, the client extends deadline a little before the deadline. This translates to scheduling deadling extension "in the past". In turn, this causes tasks to be run -- and new tasks scheduled -- without explicit calls to advance the time on the fake clock. So, when the test code actually advance the fake clock, it runs more tasks than it wants to. This PR conservatively sets the initial deadline duration to 10 seconds. This is already the default in streaming version.
1 parent 00fbd72 commit b7ba60b

3 files changed

Lines changed: 3 additions & 2 deletions

File tree

google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PollingSubscriberConnection.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public PollingSubscriberConnection(
9090
flowController,
9191
executor,
9292
clock);
93+
messageDispatcher.setMessageDeadlineSeconds(Subscriber.MIN_ACK_DEADLINE_SECONDS);
9394
}
9495

9596
@Override

google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/Subscriber.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public class Subscriber {
113113
20 * 1024 * 1024; // 20MB API maximum message size.
114114
private static final int INITIAL_ACK_DEADLINE_SECONDS = 10;
115115
private static final int MAX_ACK_DEADLINE_SECONDS = 600;
116-
private static final int MIN_ACK_DEADLINE_SECONDS = 10;
116+
static final int MIN_ACK_DEADLINE_SECONDS = 10;
117117
private static final Duration ACK_DEADLINE_UPDATE_PERIOD = Duration.standardMinutes(1);
118118
private static final double PERCENTILE_FOR_ACK_DEADLINE_UPDATES = 99.9;
119119

google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/FakeSubscriberServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
class FakeSubscriberServiceImpl extends SubscriberImplBase {
5050
private final AtomicBoolean subscriptionInitialized = new AtomicBoolean(false);
5151
private String subscription = "";
52-
private final AtomicInteger messageAckDeadline = new AtomicInteger();
52+
private final AtomicInteger messageAckDeadline = new AtomicInteger(Subscriber.MIN_ACK_DEADLINE_SECONDS);
5353
private final List<Stream> openedStreams = new ArrayList<>();
5454
private final List<Stream> closedStreams = new ArrayList<>();
5555
private final List<String> acks = new ArrayList<>();

0 commit comments

Comments
 (0)