Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.mockito.Mockito;

@RunWith(Parameterized.class)
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;
Expand Down Expand Up @@ -127,24 +127,21 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> serverCall,
Metadata metadata,
ServerCallHandler<ReqT, RespT> 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<ReqT> blackhole = Mockito.mock(ServerCall.Listener.class);
return blackhole;
return new ServerCall.Listener<ReqT>() {};
}
})
.addService(new BigtableGrpc.BigtableImplBase() {})
Expand Down Expand Up @@ -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, ...
Expand All @@ -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)));
Expand Down Expand Up @@ -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));
Expand Down
Loading