Skip to content

Commit a3bb441

Browse files
committed
xds: Fix race condition in ext-proc fail-open client interceptor test
Resolve flakiness in ExternalProcessorClientInterceptorTest's givenFailureModeAllowTrue_whenExtProcStreamFails_thenCallFailsOpen test. The test was racing because the mock sidecar failed asynchronously on headers, occasionally running after the client had already sent a request message. If the message was sent first, fail-open was disallowed because of data loss. Fixed by intercepting the data plane server to block the client thread until the data plane call actually starts (headers received). This ensures the client interceptor has processed the ext-proc stream failure and transitioned to fail-open pass-through mode before the application sends the request body.
1 parent 036c7f0 commit a3bb441

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8460,14 +8460,25 @@ public void onCompleted() {
84608460
filterConfig, channelManager, scheduler, FAKE_CONTEXT);
84618461

84628462
final CountDownLatch dataPlaneLatch = new CountDownLatch(1);
8463-
dataPlaneServiceRegistry.addService(ServerServiceDefinition.builder("test.TestService")
8464-
.addMethod(METHOD_SAY_HELLO, ServerCalls.asyncUnaryCall(
8465-
(request, responseObserver) -> {
8466-
responseObserver.onNext("Hello " + request);
8467-
responseObserver.onCompleted();
8468-
dataPlaneLatch.countDown();
8469-
}))
8470-
.build());
8463+
final CountDownLatch headersReceivedLatch = new CountDownLatch(1);
8464+
ServerInterceptor dataPlaneInterceptor = new ServerInterceptor() {
8465+
@Override
8466+
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
8467+
ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
8468+
headersReceivedLatch.countDown();
8469+
return next.startCall(call, headers);
8470+
}
8471+
};
8472+
dataPlaneServiceRegistry.addService(ServerInterceptors.intercept(
8473+
ServerServiceDefinition.builder("test.TestService")
8474+
.addMethod(METHOD_SAY_HELLO, ServerCalls.asyncUnaryCall(
8475+
(request, responseObserver) -> {
8476+
responseObserver.onNext("Hello " + request);
8477+
responseObserver.onCompleted();
8478+
dataPlaneLatch.countDown();
8479+
}))
8480+
.build(),
8481+
dataPlaneInterceptor));
84718482

84728483
ManagedChannel dataPlaneChannel = grpcCleanup.register(
84738484
InProcessChannelBuilder.forName(dataPlaneServerName).directExecutor().build());
@@ -8487,6 +8498,7 @@ public void onClose(Status status, Metadata trailers) {
84878498

84888499
// Send message and half-close to trigger unary call reaching server
84898500
proxyCall.request(1);
8501+
assertThat(headersReceivedLatch.await(5, TimeUnit.SECONDS)).isTrue();
84908502
proxyCall.sendMessage("test");
84918503
proxyCall.halfClose();
84928504

0 commit comments

Comments
 (0)