Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit ca85655

Browse files
test: deflake stub test (#2769)
Now the server tags the server contexts by method, which should prevent the priming context from leaking Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Rollback plan is reviewed and LGTMed - [ ] All new data plane features have a completed end to end testing plan Fixes #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
1 parent 871e6a3 commit ca85655

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
import io.grpc.ManagedChannelBuilder;
111111
import io.grpc.Metadata;
112112
import io.grpc.Metadata.Key;
113+
import io.grpc.MethodDescriptor;
113114
import io.grpc.Server;
114115
import io.grpc.ServerCall;
115116
import io.grpc.ServerCall.Listener;
@@ -717,7 +718,7 @@ public void testCallContextPropagatedInMutationBatcher()
717718
}
718719

719720
// Ensure that the server got the overriden deadline
720-
Context serverCtx = contextInterceptor.contexts.poll();
721+
Context serverCtx = contextInterceptor.pollContext(BigtableGrpc.getMutateRowsMethod());
721722
assertThat(serverCtx).isNotNull();
722723
assertThat(serverCtx.getDeadline()).isAtLeast(Deadline.after(8, TimeUnit.MINUTES));
723724
}
@@ -747,7 +748,7 @@ public void testCallContextPropagatedInReadBatcher()
747748
}
748749

749750
// Ensure that the server got the overriden deadline
750-
Context serverCtx = contextInterceptor.contexts.poll();
751+
Context serverCtx = contextInterceptor.pollContext(BigtableGrpc.getReadRowsMethod());
751752
assertThat(serverCtx).isNotNull();
752753
assertThat(serverCtx.getDeadline()).isAtLeast(Deadline.after(8, TimeUnit.MINUTES));
753754
}
@@ -970,16 +971,37 @@ public <ReqT, RespT> Listener<ReqT> interceptCall(
970971
}
971972

972973
private static class ContextInterceptor implements ServerInterceptor {
973-
final BlockingQueue<Context> contexts = Queues.newLinkedBlockingDeque();
974+
final BlockingQueue<MethodContext> contexts = Queues.newLinkedBlockingDeque();
975+
976+
static class MethodContext {
977+
final MethodDescriptor<?, ?> method;
978+
final Context context;
979+
980+
MethodContext(MethodDescriptor<?, ?> method, Context context) {
981+
this.method = method;
982+
this.context = context;
983+
}
984+
}
974985

975986
@Override
976987
public <ReqT, RespT> Listener<ReqT> interceptCall(
977988
ServerCall<ReqT, RespT> serverCall,
978989
Metadata metadata,
979990
ServerCallHandler<ReqT, RespT> serverCallHandler) {
980-
contexts.add(Context.current());
991+
contexts.add(new MethodContext(serverCall.getMethodDescriptor(), Context.current()));
981992
return serverCallHandler.startCall(serverCall, metadata);
982993
}
994+
995+
Context pollContext(MethodDescriptor<?, ?> method) {
996+
ContextInterceptor.MethodContext methodContext = contexts.poll();
997+
while (methodContext != null) {
998+
if (method.equals(methodContext.method)) {
999+
return methodContext.context;
1000+
}
1001+
methodContext = contexts.poll();
1002+
}
1003+
return null;
1004+
}
9831005
}
9841006

9851007
private static class FakeDataService extends BigtableGrpc.BigtableImplBase {

0 commit comments

Comments
 (0)