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

Method TestConfigUpdate_ControlChannelServiceConfig

balancer/rls/balancer_test.go:196–251  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

194// via the `routeLookupChannelServiceConfig` field. This test verifies that the
195// provided service config is applied for the control channel.
196func (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

Callers

nothing calls this directly

Calls 15

ReplaceMethod · 0.95
ReceiveMethod · 0.95
NewChannelFunction · 0.92
RegisterRLSChildPolicyFunction · 0.92
NewClientFunction · 0.92
WithResolversFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
neverThrottlingThrottlerFunction · 0.85
startBackendFunction · 0.85

Tested by

no test coverage detected