TestConfigUpdate_ControlChannelServiceConfig tests the scenario where RLS LB policy's configuration specifies the service config for the control channel via the `routeLookupChannelServiceConfig` field. This test verifies that the provided service config is applied for the control channel.
(t *testing.T)
| 194 | // via the `routeLookupChannelServiceConfig` field. This test verifies that the |
| 195 | // provided service config is applied for the control channel. |
| 196 | func (s) TestConfigUpdate_ControlChannelServiceConfig(t *testing.T) { |
| 197 | // Start an RLS server and set the throttler to never throttle requests. |
| 198 | rlsServer, rlsReqCh := rlstest.SetupFakeRLSServer(t, nil) |
| 199 | overrideAdaptiveThrottler(t, neverThrottlingThrottler()) |
| 200 | |
| 201 | // Register a balancer to be used for the control channel, and set up a |
| 202 | // callback to get notified when the balancer receives a clientConn updates. |
| 203 | ccUpdateCh := testutils.NewChannel() |
| 204 | bf := &e2e.BalancerFuncs{ |
| 205 | UpdateClientConnState: func(cfg *e2e.RLSChildPolicyConfig) error { |
| 206 | if cfg.Backend != rlsServer.Address { |
| 207 | return fmt.Errorf("control channel LB policy received config with backend %q, want %q", cfg.Backend, rlsServer.Address) |
| 208 | } |
| 209 | ccUpdateCh.Replace(nil) |
| 210 | return nil |
| 211 | }, |
| 212 | } |
| 213 | controlChannelPolicyName := "test-control-channel-" + t.Name() |
| 214 | e2e.RegisterRLSChildPolicy(controlChannelPolicyName, bf) |
| 215 | t.Logf("Registered child policy with name %q", controlChannelPolicyName) |
| 216 | |
| 217 | // Build RLS service config and set the `routeLookupChannelServiceConfig` |
| 218 | // field to a service config which uses the above balancer. |
| 219 | rlsConfig := buildBasicRLSConfigWithChildPolicy(t, t.Name(), rlsServer.Address) |
| 220 | rlsConfig.RouteLookupChannelServiceConfig = fmt.Sprintf(`{"loadBalancingConfig" : [{%q: {"backend": %q} }]}`, controlChannelPolicyName, rlsServer.Address) |
| 221 | |
| 222 | // Start a test backend, and set up the fake RLS server to return this as a |
| 223 | // target in the RLS response. |
| 224 | backendCh, backendAddress := startBackend(t) |
| 225 | rlsServer.SetResponseCallback(func(_ context.Context, _ *rlspb.RouteLookupRequest) *rlstest.RouteLookupResponse { |
| 226 | return &rlstest.RouteLookupResponse{Resp: &rlspb.RouteLookupResponse{Targets: []string{backendAddress}}} |
| 227 | }) |
| 228 | |
| 229 | // Register a manual resolver and push the RLS service config through it. |
| 230 | r := startManualResolverWithConfig(t, rlsConfig) |
| 231 | |
| 232 | cc, err := grpc.NewClient(r.Scheme()+":///rls.test.example.com", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials())) |
| 233 | if err != nil { |
| 234 | t.Fatalf("Failed to create gRPC client: %v", err) |
| 235 | } |
| 236 | defer cc.Close() |
| 237 | |
| 238 | // Make an RPC and ensure it gets routed to the test backend. |
| 239 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 240 | defer cancel() |
| 241 | makeTestRPCAndExpectItToReachBackend(ctx, t, cc, backendCh) |
| 242 | |
| 243 | // Make sure an RLS request is sent out. |
| 244 | verifyRLSRequest(t, rlsReqCh, true) |
| 245 | |
| 246 | // Verify that the control channel is using the LB policy we injected via the |
| 247 | // routeLookupChannelServiceConfig field. |
| 248 | if _, err := ccUpdateCh.Receive(ctx); err != nil { |
| 249 | t.Fatalf("timeout when waiting for control channel LB policy to receive a clientConn update") |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | // TestConfigUpdate_DefaultTarget tests the scenario where a config update |
nothing calls this directly
no test coverage detected