TestLookupFailure tests the case where the RLS server responds with an error.
(t *testing.T)
| 69 | |
| 70 | // TestLookupFailure tests the case where the RLS server responds with an error. |
| 71 | func (s) TestLookupFailure(t *testing.T) { |
| 72 | // Start an RLS server and set the throttler to never throttle requests. |
| 73 | rlsServer, _ := rlstest.SetupFakeRLSServer(t, nil) |
| 74 | overrideAdaptiveThrottler(t, neverThrottlingThrottler()) |
| 75 | |
| 76 | // Setup the RLS server to respond with errors. |
| 77 | rlsServer.SetResponseCallback(func(context.Context, *rlspb.RouteLookupRequest) *rlstest.RouteLookupResponse { |
| 78 | return &rlstest.RouteLookupResponse{Err: errors.New("rls failure")} |
| 79 | }) |
| 80 | |
| 81 | // Create a control channel to the fake RLS server. |
| 82 | ctrlCh, err := newControlChannel(rlsServer.Address, "", defaultTestTimeout, balancer.BuildOptions{}, nil) |
| 83 | if err != nil { |
| 84 | t.Fatalf("Failed to create control channel to RLS server: %v", err) |
| 85 | } |
| 86 | defer ctrlCh.close() |
| 87 | |
| 88 | // Perform the lookup and expect the callback to be invoked with an error. |
| 89 | errCh := make(chan error, 1) |
| 90 | ctrlCh.lookup(nil, rlspb.RouteLookupRequest_REASON_MISS, staleHeaderData, func(_ []string, _ string, err error) { |
| 91 | if err == nil { |
| 92 | errCh <- errors.New("rlsClient.lookup() succeeded, should have failed") |
| 93 | return |
| 94 | } |
| 95 | errCh <- nil |
| 96 | }) |
| 97 | |
| 98 | select { |
| 99 | case <-time.After(defaultTestTimeout): |
| 100 | t.Fatal("timeout when waiting for lookup callback to be invoked") |
| 101 | case err := <-errCh: |
| 102 | if err != nil { |
| 103 | t.Fatal(err) |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // TestLookupDeadlineExceeded tests the case where the RLS server does not |
| 109 | // respond within the configured rpc timeout. |
nothing calls this directly
no test coverage detected