diff --git a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x/src/test/java/com/google/cloud/bigtable/hbase/TestRetryBehavior.java b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x/src/test/java/com/google/cloud/bigtable/hbase/TestRetryBehavior.java index bfa01a07c6..a0d15e808b 100644 --- a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x/src/test/java/com/google/cloud/bigtable/hbase/TestRetryBehavior.java +++ b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x/src/test/java/com/google/cloud/bigtable/hbase/TestRetryBehavior.java @@ -58,7 +58,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import org.mockito.Mockito; @RunWith(Parameterized.class) public class TestRetryBehavior { @@ -66,6 +65,7 @@ public class TestRetryBehavior { private static final Duration DELAY = Duration.ofMillis(5); private static final Duration ATTEMPT_TIMEOUT = Duration.ofMillis(450); private static final Duration OPERATION_TIMEOUT = Duration.ofSeconds(2); + private static final Duration DEADLINE_TOLERANCE = Duration.ofMillis(100); private final TestOp testOp; private Server fakeServer; @@ -127,24 +127,21 @@ public ServerCall.Listener interceptCall( ServerCall serverCall, Metadata metadata, ServerCallHandler serverCallHandler) { - callCount.incrementAndGet(); - - // record the deadline + // record the deadline before incrementing callCount @Nullable Duration duration = Optional.ofNullable(Context.current().getDeadline()) .map(d -> Duration.ofMillis(d.timeRemaining(TimeUnit.MILLISECONDS))) .orElse(null); remainingDurations.add(duration); + callCount.incrementAndGet(); // execute test specific callback rpcRunnable.get().accept(serverCall); // Don't really care about client requests, just blackhole them // this will prevent any invocations of the stub - @SuppressWarnings("unchecked") - ServerCall.Listener blackhole = Mockito.mock(ServerCall.Listener.class); - return blackhole; + return new ServerCall.Listener() {}; } }) .addService(new BigtableGrpc.BigtableImplBase() {}) @@ -203,7 +200,9 @@ public void testRpcWillRetryOnAbort() throws Exception { Duration elapsed = stopwatch.elapsed(); Status status = extractStatus(e); - assertThat(status.getCode()).isEqualTo(Status.Code.ABORTED); + // Retries can race with the overall operation deadline, surfacing DEADLINE_EXCEEDED + // instead of ABORTED on the final attempt. + assertThat(status.getCode()).isAnyOf(Status.Code.ABORTED, Status.Code.DEADLINE_EXCEEDED); // Server immediately errors out, so exponential backoff will be the bottleneck for retries // Maximum delays will be: 5, 10, 20, 40, 80, 160, 320, 640, 1m, 1m, ... @@ -218,7 +217,7 @@ public void testRpcWillRetryOnAbort() throws Exception { // Ignoring the first attempt, because it will be unstable due to connection setup assertThat(remainingDurations.subList(1, 9)) .comparingElementsUsing(MIN_DURATION_CORRESPONDENCE) - .contains(ATTEMPT_TIMEOUT.minus(Duration.ofMillis(5))); + .contains(ATTEMPT_TIMEOUT.minus(DEADLINE_TOLERANCE)); // but should still be limited by the operation timeout with some jitter assertThat(elapsed).isAtMost(OPERATION_TIMEOUT.plus(ATTEMPT_TIMEOUT.dividedBy(2))); @@ -257,7 +256,7 @@ public void testRpcWillRespectAttemptTimeout() throws IOException { // Ignoring the first and last attempt, all attempts should be just under attempt timeout assertThat(remainingDurations.subList(1, remainingDurations.size() - 1)) .comparingElementsUsing(MIN_DURATION_CORRESPONDENCE) - .contains(ATTEMPT_TIMEOUT.minus(Duration.ofMillis(10))); + .contains(ATTEMPT_TIMEOUT.minus(DEADLINE_TOLERANCE)); // Altogether should still be limited by the operation timeout with some jitter assertThat(elapsed).isAtMost(OPERATION_TIMEOUT.plus(ATTEMPT_TIMEOUT));