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

Method TestConfigUpdate_ChildPolicyConfigs

balancer/rls/balancer_test.go:296–420  ·  balancer/rls/balancer_test.go::s.TestConfigUpdate_ChildPolicyConfigs

TestConfigUpdate_ChildPolicyConfigs verifies that config changes which affect child policy configuration are propagated correctly.

(t *testing.T)

Source from the content-addressed store, hash-verified

294// TestConfigUpdate_ChildPolicyConfigs verifies that config changes which affect
295// child policy configuration are propagated correctly.
296func (s) TestConfigUpdate_ChildPolicyConfigs(t *testing.T) {
297 // Start an RLS server and set the throttler to never throttle requests.
298 rlsServer, rlsReqCh := rlstest.SetupFakeRLSServer(t, nil)
299 overrideAdaptiveThrottler(t, neverThrottlingThrottler())
300
301 // Start a default backend and a test backend.
302 _, defBackendAddress := startBackend(t)
303 testBackendCh, testBackendAddress := startBackend(t)
304
305 // Set up the RLS server to respond with the test backend.
306 rlsServer.SetResponseCallback(func(_ context.Context, _ *rlspb.RouteLookupRequest) *rlstest.RouteLookupResponse {
307 return &rlstest.RouteLookupResponse{Resp: &rlspb.RouteLookupResponse{Targets: []string{testBackendAddress}}}
308 })
309
310 // Set up a test balancer callback to push configs received by child policies.
311 defBackendConfigsCh := make(chan *e2e.RLSChildPolicyConfig, 1)
312 testBackendConfigsCh := make(chan *e2e.RLSChildPolicyConfig, 1)
313 bf := &e2e.BalancerFuncs{
314 UpdateClientConnState: func(cfg *e2e.RLSChildPolicyConfig) error {
315 switch cfg.Backend {
316 case defBackendAddress:
317 defBackendConfigsCh <- cfg
318 case testBackendAddress:
319 testBackendConfigsCh <- cfg
320 default:
321 t.Errorf("Received child policy configs for unknown target %q", cfg.Backend)
322 }
323 return nil
324 },
325 }
326
327 // Register an LB policy to act as the child policy for RLS LB policy.
328 childPolicyName := "test-child-policy" + t.Name()
329 e2e.RegisterRLSChildPolicy(childPolicyName, bf)
330 t.Logf("Registered child policy with name %q", childPolicyName)
331
332 // Build RLS service config with default target.
333 rlsConfig := buildBasicRLSConfig(childPolicyName, rlsServer.Address)
334 rlsConfig.RouteLookupConfig.DefaultTarget = defBackendAddress
335
336 // Register a manual resolver and push the RLS service config through it.
337 r := startManualResolverWithConfig(t, rlsConfig)
338
339 cc, err := grpc.NewClient(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()))
340 if err != nil {
341 t.Fatalf("grpc.NewClient() failed: %v", err)
342 }
343 defer cc.Close()
344 cc.Connect()
345
346 // At this point, the RLS LB policy should have received its config, and
347 // should have created a child policy for the default target.
348 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
349 defer cancel()
350 wantCfg := &e2e.RLSChildPolicyConfig{Backend: defBackendAddress}
351 select {
352 case <-ctx.Done():
353 t.Fatal("Timed out when waiting for the default target child policy to receive its config")

Callers

nothing calls this directly

Calls 15

RegisterRLSChildPolicyFunction · 0.92
NewClientFunction · 0.92
WithResolversFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
GetFunction · 0.92
neverThrottlingThrottlerFunction · 0.85
startBackendFunction · 0.85
buildBasicRLSConfigFunction · 0.85

Tested by

no test coverage detected