Skip to content

Commit 899c50b

Browse files
authored
test: fix flaky vip_java_bigtable test (#2116)
1 parent 4d70dee commit 899c50b

File tree

1 file changed

+17
-10
lines changed
  • google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub

1 file changed

+17
-10
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public class RetryInfoTest {
8888
private BigtableDataSettings.Builder settings;
8989

9090
private AtomicInteger attemptCounter = new AtomicInteger();
91-
private com.google.protobuf.Duration delay =
91+
private com.google.protobuf.Duration defaultDelay =
9292
com.google.protobuf.Duration.newBuilder().setSeconds(2).setNanos(0).build();
9393

9494
@Before
@@ -328,7 +328,7 @@ public void testCheckAndMutateDisableRetryInfo() throws IOException {
328328
settings.stubSettings().setEnableRetryInfo(false);
329329

330330
try (BigtableDataClient client = BigtableDataClient.create(settings.build())) {
331-
ApiException exception = enqueueNonRetryableExceptionWithDelay(delay);
331+
ApiException exception = enqueueNonRetryableExceptionWithDelay(defaultDelay);
332332
try {
333333
client.checkAndMutateRow(
334334
ConditionalRowMutation.create("table", "key")
@@ -382,7 +382,7 @@ public void testReadModifyWriteDisableRetryInfo() throws IOException {
382382
settings.stubSettings().setEnableRetryInfo(false);
383383

384384
try (BigtableDataClient client = BigtableDataClient.create(settings.build())) {
385-
ApiException exception = enqueueNonRetryableExceptionWithDelay(delay);
385+
ApiException exception = enqueueNonRetryableExceptionWithDelay(defaultDelay);
386386
try {
387387
client.readModifyWriteRow(ReadModifyWriteRow.create("table", "row").append("cf", "q", "v"));
388388
} catch (ApiException e) {
@@ -460,7 +460,8 @@ public void testReadChangeStreamNotReturningRetryInfoClientDisabledHandling() th
460460
.readChangeStream(ReadChangeStreamQuery.create("table"))
461461
.iterator()
462462
.hasNext(),
463-
true);
463+
true,
464+
com.google.protobuf.Duration.newBuilder().setSeconds(5).setNanos(0).build());
464465
}
465466
}
466467

@@ -507,30 +508,30 @@ public void testGenerateInitialChangeStreamServerNotReturningRetryInfoClientDisa
507508
// Test the case where server returns retry info and client enables handling of retry info
508509
private void verifyRetryInfoIsUsed(Runnable runnable, boolean retryableError) {
509510
if (retryableError) {
510-
enqueueRetryableExceptionWithDelay(delay);
511+
enqueueRetryableExceptionWithDelay(defaultDelay);
511512
} else {
512-
enqueueNonRetryableExceptionWithDelay(delay);
513+
enqueueNonRetryableExceptionWithDelay(defaultDelay);
513514
}
514515
Stopwatch stopwatch = Stopwatch.createStarted();
515516
runnable.run();
516517
stopwatch.stop();
517518

518519
assertThat(attemptCounter.get()).isEqualTo(2);
519-
assertThat(stopwatch.elapsed()).isAtLeast(Duration.ofSeconds(delay.getSeconds()));
520+
assertThat(stopwatch.elapsed()).isAtLeast(Duration.ofSeconds(defaultDelay.getSeconds()));
520521
}
521522

522523
// Test the case where server returns retry info but client disabled handling of retry info
523524
private void verifyRetryInfoCanBeDisabled(Runnable runnable) {
524-
enqueueRetryableExceptionWithDelay(delay);
525+
enqueueRetryableExceptionWithDelay(defaultDelay);
525526
Stopwatch stopwatch = Stopwatch.createStarted();
526527
runnable.run();
527528
stopwatch.stop();
528529

529530
assertThat(attemptCounter.get()).isEqualTo(2);
530-
assertThat(stopwatch.elapsed()).isLessThan(Duration.ofSeconds(delay.getSeconds()));
531+
assertThat(stopwatch.elapsed()).isLessThan(Duration.ofSeconds(defaultDelay.getSeconds()));
531532

532533
attemptCounter.set(0);
533-
ApiException expectedApiException = enqueueNonRetryableExceptionWithDelay(delay);
534+
ApiException expectedApiException = enqueueNonRetryableExceptionWithDelay(defaultDelay);
534535
ApiException actualException =
535536
assertThrows("non retryable operations should fail", ApiException.class, runnable::run);
536537
if (actualException instanceof MutateRowsException) {
@@ -549,6 +550,12 @@ private void verifyRetryInfoCanBeDisabled(Runnable runnable) {
549550

550551
// Test the case where server does not return retry info
551552
private void verifyNoRetryInfo(Runnable runnable, boolean operationRetryable) {
553+
verifyNoRetryInfo(runnable, operationRetryable, defaultDelay);
554+
}
555+
556+
// individual test can override the default delay
557+
private void verifyNoRetryInfo(
558+
Runnable runnable, boolean operationRetryable, com.google.protobuf.Duration delay) {
552559
enqueueRetryableExceptionNoRetryInfo();
553560

554561
if (!operationRetryable) {

0 commit comments

Comments
 (0)