Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remote execution tests #18800

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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 @@ -21,6 +21,7 @@
import static org.mockito.AdditionalAnswers.answerVoid;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import build.bazel.remote.execution.v2.Action;
Expand Down Expand Up @@ -811,10 +812,9 @@ public void updateActionResult(
}
}
});
ByteStreamImplBase mockByteStreamImpl = Mockito.mock(ByteStreamImplBase.class);
ByteStreamImplBase mockByteStreamImpl = spy(ByteStreamImplBase.class);
serviceRegistry.addService(mockByteStreamImpl);
when(mockByteStreamImpl.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any()))
.thenAnswer(
doAnswer(
new Answer<StreamObserver<WriteRequest>>() {
private int numErrors = 4;

Expand Down Expand Up @@ -865,7 +865,9 @@ public void onError(Throwable t) {
}
};
}
});
})
.when(mockByteStreamImpl)
.write(any());
doAnswer(
answerVoid(
(QueryWriteStatusRequest request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.mockito.AdditionalAnswers.answerVoid;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -729,9 +730,8 @@ public void findMissingBlobs(
};
serviceRegistry.addService(ServerInterceptors.intercept(cas, new RequestHeadersValidator()));

ByteStreamImplBase mockByteStreamImpl = Mockito.mock(ByteStreamImplBase.class);
when(mockByteStreamImpl.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any()))
.thenAnswer(blobWriteAnswer("xyz".getBytes(UTF_8)));
ByteStreamImplBase mockByteStreamImpl = spy(ByteStreamImplBase.class);
doAnswer(blobWriteAnswer("xyz".getBytes(UTF_8))).when(mockByteStreamImpl).write(any());
serviceRegistry.addService(
ServerInterceptors.intercept(mockByteStreamImpl, new RequestHeadersValidator()));

Expand Down Expand Up @@ -807,23 +807,23 @@ public void getActionResult(
.setResponse(Any.pack(ExecuteResponse.newBuilder().setResult(actionResult).build()))
.build();

ExecutionImplBase mockExecutionImpl = Mockito.mock(ExecutionImplBase.class);
ExecutionImplBase mockExecutionImpl = spy(ExecutionImplBase.class);
// Flow of this test:
// - call execute, get retriable gRPC error
// - retry: call execute, get retriable Operation error
// - retry: call execute, get an Operation, then a retriable gRPC error
// - retry: call waitExecute, get a retriable gRPC error
// - retry: call waitExecute, get retriable Operation error
// - retry: call execute, get successful operation, ignore further errors.
Mockito.doAnswer(answerWith(null, Status.UNAVAILABLE))
doAnswer(answerWith(null, Status.UNAVAILABLE))
.doAnswer(answerWith(operationWithExecuteError, Status.OK))
.doAnswer(answerWith(unfinishedOperation, Status.UNAVAILABLE))
.doAnswer(answerWith(opSuccess, Status.UNAVAILABLE)) // last status should be ignored.
.when(mockExecutionImpl)
.execute(
ArgumentMatchers.<ExecuteRequest>any(),
ArgumentMatchers.<StreamObserver<Operation>>any());
Mockito.doAnswer(answerWith(null, Status.UNAVAILABLE))
doAnswer(answerWith(null, Status.UNAVAILABLE))
.doAnswer(answerWith(operationWithExecuteError, Status.OK))
.when(mockExecutionImpl)
.waitExecution(
Expand Down Expand Up @@ -853,11 +853,12 @@ public void findMissingBlobs(
}
});

ByteStreamImplBase mockByteStreamImpl = Mockito.mock(ByteStreamImplBase.class);
when(mockByteStreamImpl.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any()))
.thenAnswer(blobWriteAnswerError()) // Error on the input file.
.thenAnswer(blobWriteAnswerError()) // Error on the input file again.
.thenAnswer(blobWriteAnswer("xyz".getBytes(UTF_8))); // Upload input file successfully.
ByteStreamImplBase mockByteStreamImpl = spy(ByteStreamImplBase.class);
doAnswer(blobWriteAnswerError()) // Error on the input file.
.doAnswer(blobWriteAnswerError()) // Error on the input file again.
.doAnswer(blobWriteAnswer("xyz".getBytes(UTF_8))) // Upload input file successfully.
.when(mockByteStreamImpl)
.write(any());
doAnswer(
answerVoid(
(QueryWriteStatusRequest request,
Expand All @@ -871,7 +872,7 @@ public void findMissingBlobs(
}))
.when(mockByteStreamImpl)
.queryWriteStatus(any(), any());
Mockito.doAnswer(
doAnswer(
invocationOnMock -> {
@SuppressWarnings("unchecked")
StreamObserver<ReadResponse> responseObserver =
Expand Down Expand Up @@ -951,26 +952,22 @@ public void getActionResult(
.setResponse(Any.pack(ExecuteResponse.newBuilder().setResult(actionResult).build()))
.build();

ExecutionImplBase mockExecutionImpl = Mockito.mock(ExecutionImplBase.class);
ExecutionImplBase mockExecutionImpl = spy(ExecutionImplBase.class);
// Flow of this test:
// - call execute, get an Operation, then a retriable gRPC error
// - retry: call waitExecute, get NOT_FOUND (operation lost)
// - retry: call execute, get NOT_FOUND (operation lost)
// - retry: call execute, get an Operation, then a retriable gRPC error
// - retry: call waitExecute, get successful operation, ignore further errors.
Mockito.doAnswer(answerWith(unfinishedOperation, Status.UNAVAILABLE))
doAnswer(answerWith(unfinishedOperation, Status.UNAVAILABLE))
.doAnswer(answerWith(unfinishedOperation, Status.NOT_FOUND))
.doAnswer(answerWith(unfinishedOperation, Status.UNAVAILABLE))
.when(mockExecutionImpl)
.execute(
ArgumentMatchers.<ExecuteRequest>any(),
ArgumentMatchers.<StreamObserver<Operation>>any());
Mockito.doAnswer(answerWith(unfinishedOperation, Status.NOT_FOUND))
.execute(any(), any());
doAnswer(answerWith(unfinishedOperation, Status.NOT_FOUND))
.doAnswer(answerWith(opSuccess, Status.UNAVAILABLE)) // This error is ignored.
.when(mockExecutionImpl)
.waitExecution(
ArgumentMatchers.<WaitExecutionRequest>any(),
ArgumentMatchers.<StreamObserver<Operation>>any());
.waitExecution(any(), any());
serviceRegistry.addService(mockExecutionImpl);

serviceRegistry.addService(
Expand All @@ -989,10 +986,9 @@ public void findMissingBlobs(
}
});

ByteStreamImplBase mockByteStreamImpl = Mockito.mock(ByteStreamImplBase.class);
when(mockByteStreamImpl.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any()))
.thenAnswer(blobWriteAnswer("xyz".getBytes(UTF_8))); // Upload input file successfully.
Mockito.doAnswer(
ByteStreamImplBase mockByteStreamImpl = spy(ByteStreamImplBase.class);
doAnswer(blobWriteAnswer("xyz".getBytes(UTF_8))).when(mockByteStreamImpl).write(any());
doAnswer(
invocationOnMock -> {
@SuppressWarnings("unchecked")
StreamObserver<ReadResponse> responseObserver =
Expand Down Expand Up @@ -1508,17 +1504,17 @@ public void read(ReadRequest request, StreamObserver<ReadResponse> responseObser
.build();
final WaitExecutionRequest waitExecutionRequest =
WaitExecutionRequest.newBuilder().setName(opName).build();
ExecutionImplBase mockExecutionImpl = Mockito.mock(ExecutionImplBase.class);
ExecutionImplBase mockExecutionImpl = spy(ExecutionImplBase.class);
// Flow of this test:
// - call execute, get an unfinished Operation, then the stream completes
// - call waitExecute, get an unfinished Operation, then the stream completes
// - call waitExecute, get a finished Operation
Mockito.doAnswer(answerWith(unfinishedOperation, Status.OK))
doAnswer(answerWith(unfinishedOperation, Status.OK))
.when(mockExecutionImpl)
.execute(
ArgumentMatchers.<ExecuteRequest>any(),
ArgumentMatchers.<StreamObserver<Operation>>any());
Mockito.doAnswer(answerWith(unfinishedOperation, Status.OK))
doAnswer(answerWith(unfinishedOperation, Status.OK))
.doAnswer(answerWith(completeOperation, Status.OK))
.when(mockExecutionImpl)
.waitExecution(
Expand Down
Loading