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

Function testControlChannelCredsSuccess

balancer/rls/control_channel_test.go:257–305  ·  view source on GitHub ↗
(t *testing.T, sopts []grpc.ServerOption, bopts balancer.BuildOptions)

Source from the content-addressed store, hash-verified

255)
256
257func testControlChannelCredsSuccess(t *testing.T, sopts []grpc.ServerOption, bopts balancer.BuildOptions) {
258 // Start an RLS server and set the throttler to never throttle requests.
259 rlsServer, _ := rlstest.SetupFakeRLSServer(t, nil, sopts...)
260 overrideAdaptiveThrottler(t, neverThrottlingThrottler())
261
262 // Setup the RLS server to respond with a valid response.
263 rlsServer.SetResponseCallback(func(context.Context, *rlspb.RouteLookupRequest) *rlstest.RouteLookupResponse {
264 return lookupResponse
265 })
266
267 // Verify that the request received by the RLS matches the expected one.
268 rlsServer.SetRequestCallback(func(got *rlspb.RouteLookupRequest) {
269 if diff := cmp.Diff(lookupRequest, got, cmp.Comparer(proto.Equal)); diff != "" {
270 t.Errorf("RouteLookupRequest diff (-want, +got):\n%s", diff)
271 }
272 })
273
274 // Create a control channel to the fake server.
275 ctrlCh, err := newControlChannel(rlsServer.Address, "", defaultTestTimeout, bopts, nil)
276 if err != nil {
277 t.Fatalf("Failed to create control channel to RLS server: %v", err)
278 }
279 defer ctrlCh.close()
280
281 // Perform the lookup and expect a successful callback invocation.
282 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
283 defer cancel()
284 errCh := make(chan error, 1)
285 ctrlCh.lookup(keyMap, rlspb.RouteLookupRequest_REASON_MISS, staleHeaderData, func(targets []string, headerData string, err error) {
286 if err != nil {
287 errCh <- fmt.Errorf("rlsClient.lookup() failed with err: %v", err)
288 return
289 }
290 if !cmp.Equal(targets, wantTargets) || headerData != wantHeaderData {
291 errCh <- fmt.Errorf("rlsClient.lookup() = (%v, %s), want (%v, %s)", targets, headerData, wantTargets, wantHeaderData)
292 return
293 }
294 errCh <- nil
295 })
296
297 select {
298 case <-ctx.Done():
299 t.Fatal("timeout when waiting for lookup callback to be invoked")
300 case err := <-errCh:
301 if err != nil {
302 t.Fatal(err)
303 }
304 }
305}
306
307// TestControlChannelCredsSuccess tests creation of the control channel with
308// different credentials, which are expected to succeed.

Callers 1

Calls 12

neverThrottlingThrottlerFunction · 0.85
newControlChannelFunction · 0.85
SetResponseCallbackMethod · 0.80
SetRequestCallbackMethod · 0.80
ErrorfMethod · 0.65
FatalfMethod · 0.65
EqualMethod · 0.65
FatalMethod · 0.65
closeMethod · 0.45
lookupMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected