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

Method TestConfigUpdate_ChildPolicyChange

balancer/rls/balancer_test.go:424–515  ·  view source on GitHub ↗

TestConfigUpdate_ChildPolicyChange verifies that a child policy change is handled by closing the old balancer and creating a new one.

(t *testing.T)

Source from the content-addressed store, hash-verified

422// TestConfigUpdate_ChildPolicyChange verifies that a child policy change is
423// handled by closing the old balancer and creating a new one.
424func (s) TestConfigUpdate_ChildPolicyChange(t *testing.T) {
425 // Start an RLS server and set the throttler to never throttle requests.
426 rlsServer, _ := rlstest.SetupFakeRLSServer(t, nil)
427 overrideAdaptiveThrottler(t, neverThrottlingThrottler())
428
429 // Set up balancer callbacks.
430 configsCh1 := make(chan *e2e.RLSChildPolicyConfig, 1)
431 closeCh1 := make(chan struct{}, 1)
432 bf := &e2e.BalancerFuncs{
433 UpdateClientConnState: func(cfg *e2e.RLSChildPolicyConfig) error {
434 configsCh1 <- cfg
435 return nil
436 },
437 Close: func() {
438 closeCh1 <- struct{}{}
439 },
440 }
441
442 // Register an LB policy to act as the child policy for RLS LB policy.
443 childPolicyName1 := "test-child-policy-1" + t.Name()
444 e2e.RegisterRLSChildPolicy(childPolicyName1, bf)
445 t.Logf("Registered child policy with name %q", childPolicyName1)
446
447 // Build RLS service config with a dummy default target.
448 const defaultBackend = "default-backend"
449 rlsConfig := buildBasicRLSConfig(childPolicyName1, rlsServer.Address)
450 rlsConfig.RouteLookupConfig.DefaultTarget = defaultBackend
451
452 // Register a manual resolver and push the RLS service config through it.
453 r := startManualResolverWithConfig(t, rlsConfig)
454
455 cc, err := grpc.NewClient(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()))
456 if err != nil {
457 t.Fatalf("grpc.NewClient() failed: %v", err)
458 }
459 defer cc.Close()
460 cc.Connect()
461
462 // At this point, the RLS LB policy should have received its config, and
463 // should have created a child policy for the default target.
464 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
465 defer cancel()
466 wantCfg := &e2e.RLSChildPolicyConfig{Backend: defaultBackend}
467 select {
468 case <-ctx.Done():
469 t.Fatal("Timed out when waiting for the first child policy to receive its config")
470 case gotCfg := <-configsCh1:
471 if !cmp.Equal(gotCfg, wantCfg) {
472 t.Fatalf("First child policy received config %+v, want %+v", gotCfg, wantCfg)
473 }
474 }
475
476 // Set up balancer callbacks for the second policy.
477 configsCh2 := make(chan *e2e.RLSChildPolicyConfig, 1)
478 bf = &e2e.BalancerFuncs{
479 UpdateClientConnState: func(cfg *e2e.RLSChildPolicyConfig) error {
480 configsCh2 <- cfg
481 return nil

Callers

nothing calls this directly

Calls 15

RegisterRLSChildPolicyFunction · 0.92
NewClientFunction · 0.92
WithResolversFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
neverThrottlingThrottlerFunction · 0.85
buildBasicRLSConfigFunction · 0.85
ServiceConfigJSONMethod · 0.80
NameMethod · 0.65
LogfMethod · 0.65

Tested by

no test coverage detected