TestLookupDeadlineExceeded tests the case where the RLS server does not respond within the configured rpc timeout.
(t *testing.T)
| 108 | // TestLookupDeadlineExceeded tests the case where the RLS server does not |
| 109 | // respond within the configured rpc timeout. |
| 110 | func (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. |
| 148 | type testCredsBundle struct { |
nothing calls this directly
no test coverage detected