MCPcopy
hub / github.com/grpc/grpc-go / TestLookupDeadlineExceeded

Method TestLookupDeadlineExceeded

balancer/rls/control_channel_test.go:110–145  ·  view source on GitHub ↗

TestLookupDeadlineExceeded tests the case where the RLS server does not respond within the configured rpc timeout.

(t *testing.T)

Source from the content-addressed store, hash-verified

108// TestLookupDeadlineExceeded tests the case where the RLS server does not
109// respond within the configured rpc timeout.
110func (s) TestLookupDeadlineExceeded(t *testing.T) {
111 // A unary interceptor which returns a status error with DeadlineExceeded.
112 interceptor := func(context.Context, any, *grpc.UnaryServerInfo, grpc.UnaryHandler) (resp any, err error) {
113 return nil, status.Error(codes.DeadlineExceeded, "deadline exceeded")
114 }
115
116 // Start an RLS server and set the throttler to never throttle.
117 rlsServer, _ := rlstest.SetupFakeRLSServer(t, nil, grpc.UnaryInterceptor(interceptor))
118 overrideAdaptiveThrottler(t, neverThrottlingThrottler())
119
120 // Create a control channel with a small deadline.
121 ctrlCh, err := newControlChannel(rlsServer.Address, "", defaultTestShortTimeout, balancer.BuildOptions{}, nil)
122 if err != nil {
123 t.Fatalf("Failed to create control channel to RLS server: %v", err)
124 }
125 defer ctrlCh.close()
126
127 // Perform the lookup and expect the callback to be invoked with an error.
128 errCh := make(chan error, 1)
129 ctrlCh.lookup(nil, rlspb.RouteLookupRequest_REASON_MISS, staleHeaderData, func(_ []string, _ string, err error) {
130 if st, ok := status.FromError(err); !ok || st.Code() != codes.DeadlineExceeded {
131 errCh <- fmt.Errorf("rlsClient.lookup() returned error: %v, want %v", err, codes.DeadlineExceeded)
132 return
133 }
134 errCh <- nil
135 })
136
137 select {
138 case <-time.After(defaultTestTimeout):
139 t.Fatal("timeout when waiting for lookup callback to be invoked")
140 case err := <-errCh:
141 if err != nil {
142 t.Fatal(err)
143 }
144 }
145}
146
147// testCredsBundle wraps a test call creds and real transport creds.
148type testCredsBundle struct {

Callers

nothing calls this directly

Calls 12

ErrorFunction · 0.92
UnaryInterceptorFunction · 0.92
FromErrorFunction · 0.92
neverThrottlingThrottlerFunction · 0.85
newControlChannelFunction · 0.85
CodeMethod · 0.80
FatalfMethod · 0.65
ErrorfMethod · 0.65
FatalMethod · 0.65
closeMethod · 0.45
lookupMethod · 0.45

Tested by

no test coverage detected