Skip to content

Commit f270d8f

Browse files
committed
Extend response drain test to verify handshake completion.
Extend givenResponseDrainActive_whenAppRequestsMessages_thenRequestsBuffered to complete the response draining handshake and verify that buffered requests are then successfully sent to the data plane. TAG=agy CONV=2c1e4760-c239-4698-810a-162bf10fccc4
1 parent 89dd6bf commit f270d8f

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

xds/src/test/java/io/grpc/xds/ExternalProcessorClientInterceptorTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9022,13 +9022,17 @@ public void givenResponseDrainActive_whenAppRequestsMessages_thenRequestsBuffere
90229022
final CountDownLatch drainSentLatch = new CountDownLatch(1);
90239023
final CountDownLatch headersReceivedLatch = new CountDownLatch(1);
90249024
final CountDownLatch sendDrainLatch = new CountDownLatch(1);
9025+
final CountDownLatch filterSentDrainCompleteLatch = new CountDownLatch(1);
9026+
final AtomicReference<StreamObserver<ProcessingResponse>> responseObserverRef =
9027+
new AtomicReference<>();
90259028
// External Processor Server
90269029
ExternalProcessorGrpc.ExternalProcessorImplBase extProcImpl;
90279030
extProcImpl = new ExternalProcessorGrpc.ExternalProcessorImplBase() {
90289031
@Override
90299032
@SuppressWarnings("unchecked")
90309033
public StreamObserver<ProcessingRequest> process(
90319034
final StreamObserver<ProcessingResponse> responseObserver) {
9035+
responseObserverRef.set(responseObserver);
90329036
((ServerCallStreamObserver<ProcessingResponse>) responseObserver).request(100);
90339037
return new StreamObserver<ProcessingRequest>() {
90349038
@Override
@@ -9048,6 +9052,10 @@ public void onNext(ProcessingRequest request) {
90489052
System.out.println("JetskiDebug: error in mock server: " + e);
90499053
}
90509054
}).start();
9055+
} else if (request.hasResponseBody()) {
9056+
if (request.getResponseBody().getDrainComplete()) {
9057+
filterSentDrainCompleteLatch.countDown();
9058+
}
90519059
}
90529060
}
90539061

@@ -9123,6 +9131,27 @@ public void request(int numMessages) {
91239131

91249132
// Verify requests are buffered and not sent to data plane
91259133
assertThat(dataPlaneRequestCount.get()).isEqualTo(0);
9134+
9135+
// Wait for filter to send drain_complete to mock server
9136+
assertThat(filterSentDrainCompleteLatch.await(5, TimeUnit.SECONDS)).isTrue();
9137+
9138+
// Echo drain_complete back to filter to complete handshake
9139+
synchronized (responseObserverRef.get()) {
9140+
responseObserverRef.get().onNext(ProcessingResponse.newBuilder()
9141+
.setResponseBody(BodyResponse.newBuilder()
9142+
.setResponse(CommonResponse.newBuilder()
9143+
.setBodyMutation(BodyMutation.newBuilder()
9144+
.setStreamedResponse(StreamedBodyResponse.newBuilder()
9145+
.setDrainComplete(true)
9146+
.build())
9147+
.build())
9148+
.build())
9149+
.build())
9150+
.build());
9151+
}
9152+
9153+
// Verify requests are now drained to data plane
9154+
assertThat(dataPlaneRequestCount.get()).isEqualTo(3);
91269155

91279156
proxyCall.cancel("Cleanup", null);
91289157
channelManager.close();

0 commit comments

Comments
 (0)