Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit 2d9c711

Browse files
committed
test: Deflake plan refresh deadline test
Change-Id: I1605f65fe7053adee9e88387c8fcfbe60736be07
1 parent 202b211 commit 2d9c711

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/PlanRefreshingCallableTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ public void planRefreshDelayIsFactoredIntoExecuteTimeout() throws InterruptedExc
258258
ExecuteQueryCallContext callContext =
259259
ExecuteQueryCallContext.create(preparedStatement.bind().build(), metadataFuture);
260260

261-
Duration originalAttemptTimeout = Duration.ofMillis(100);
261+
// Simulate delay for prepare response
262+
int prepareDelayMs = 50;
262263
scheduler.schedule(
263264
() -> {
264265
prepareFuture.set(
@@ -267,21 +268,25 @@ public void planRefreshDelayIsFactoredIntoExecuteTimeout() throws InterruptedExc
267268
ByteString.copyFromUtf8("initialPlan"),
268269
metadata(columnMetadata("strCol", stringType())))));
269270
},
270-
50,
271+
prepareDelayMs,
271272
TimeUnit.MILLISECONDS);
273+
274+
Duration originalAttemptTimeout = Duration.ofMillis(5000);
272275
ApiCallContext context =
273276
GrpcCallContext.createDefault().withTimeoutDuration(originalAttemptTimeout);
274-
// prepare takes 50 ms to resolve. Despite that the execute timeout should be around 100ms from
275-
// now (w padding)
276-
Deadline paddedDeadlineAtStartOfCall =
277-
Deadline.after(originalAttemptTimeout.toMillis() + 5, TimeUnit.MILLISECONDS);
277+
Instant startOfCall = Instant.now();
278278
callable.call(callContext, outerObserver, context);
279279
scheduler.shutdown();
280280
scheduler.awaitTermination(30, TimeUnit.SECONDS);
281281
GrpcCallContext grpcCallContext =
282282
(GrpcCallContext) innerCallable.popLastCall().getApiCallContext();
283+
284+
// Deadline should be at most (original deadline - prepare delay). Add 1ms to avoid flakiness.
285+
Deadline deadlineUpperBound =
286+
Deadline.after(
287+
originalAttemptTimeout.toMillis() - prepareDelayMs + 1, TimeUnit.MILLISECONDS);
283288
Deadline executeDeadline = grpcCallContext.getCallOptions().getDeadline();
284-
assertThat(executeDeadline.isBefore(paddedDeadlineAtStartOfCall)).isTrue();
289+
assertThat(executeDeadline.isBefore(deadlineUpperBound)).isTrue();
285290
}
286291

287292
@Test

0 commit comments

Comments
 (0)