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

Method TestLookupFailure

balancer/rls/control_channel_test.go:71–106  ·  view source on GitHub ↗

TestLookupFailure tests the case where the RLS server responds with an error.

(t *testing.T)

Source from the content-addressed store, hash-verified

69
70// TestLookupFailure tests the case where the RLS server responds with an error.
71func (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.

Callers

nothing calls this directly

Calls 8

neverThrottlingThrottlerFunction · 0.85
newControlChannelFunction · 0.85
SetResponseCallbackMethod · 0.80
FatalfMethod · 0.65
FatalMethod · 0.65
closeMethod · 0.45
lookupMethod · 0.45

Tested by

no test coverage detected