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

Function testControlChannelCredsFailure

balancer/rls/control_channel_test.go:353–387  ·  view source on GitHub ↗
(t *testing.T, sopts []grpc.ServerOption, bopts balancer.BuildOptions, wantCode codes.Code, wantErrRegex *regexp.Regexp)

Source from the content-addressed store, hash-verified

351}
352
353func testControlChannelCredsFailure(t *testing.T, sopts []grpc.ServerOption, bopts balancer.BuildOptions, wantCode codes.Code, wantErrRegex *regexp.Regexp) {
354 // StartFakeRouteLookupServer a fake server.
355 //
356 // Start an RLS server and set the throttler to never throttle requests. The
357 // creds failures happen before the RPC handler on the server is invoked.
358 // So, there is need to setup the request and responses on the fake server.
359 rlsServer, _ := rlstest.SetupFakeRLSServer(t, nil, sopts...)
360 overrideAdaptiveThrottler(t, neverThrottlingThrottler())
361
362 // Create the control channel to the fake server.
363 ctrlCh, err := newControlChannel(rlsServer.Address, "", defaultTestTimeout, bopts, nil)
364 if err != nil {
365 t.Fatalf("Failed to create control channel to RLS server: %v", err)
366 }
367 defer ctrlCh.close()
368
369 // Perform the lookup and expect the callback to be invoked with an error.
370 errCh := make(chan error, 1)
371 ctrlCh.lookup(nil, rlspb.RouteLookupRequest_REASON_MISS, staleHeaderData, func(_ []string, _ string, err error) {
372 if st, ok := status.FromError(err); !ok || st.Code() != wantCode || !wantErrRegex.MatchString(st.String()) {
373 errCh <- fmt.Errorf("rlsClient.lookup() returned error: %v, wantCode: %v, wantErr: %s", err, wantCode, wantErrRegex.String())
374 return
375 }
376 errCh <- nil
377 })
378
379 select {
380 case <-time.After(defaultTestTimeout):
381 t.Fatal("timeout when waiting for lookup callback to be invoked")
382 case err := <-errCh:
383 if err != nil {
384 t.Fatal(err)
385 }
386 }
387}
388
389// TestControlChannelCredsFailure tests creation of the control channel with
390// different credentials, which are expected to fail.

Callers 1

Calls 11

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

Tested by

no test coverage detected