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

Method Test_RLSFailedPicksMetric

balancer/rls/picker_test.go:342–376  ·  view source on GitHub ↗

Test_RLSFailedPicksMetric tests the failed picks metric. It configures an RLS Balancer to fail a pick with unavailable, and makes an RPC on a Channel containing this RLS Balancer. This test then asserts a failed picks metric is emitted, and default target pick or target pick metric is not emitted.

(t *testing.T)

Source from the content-addressed store, hash-verified

340// containing this RLS Balancer. This test then asserts a failed picks metric is
341// emitted, and default target pick or target pick metric is not emitted.
342func (s) Test_RLSFailedPicksMetric(t *testing.T) {
343 // Start an RLS server and set the throttler to never throttle requests.
344 rlsServer, _ := rlstest.SetupFakeRLSServer(t, nil)
345 overrideAdaptiveThrottler(t, neverThrottlingThrottler())
346
347 // Build an RLS config without a default target.
348 rlsConfig := buildBasicRLSConfigWithChildPolicy(t, t.Name(), rlsServer.Address)
349
350 // Register a manual resolver and push the RLS service config through it.
351 r := startManualResolverWithConfig(t, rlsConfig)
352
353 tmr := stats.NewTestMetricsRecorder()
354 // Dial the backend.
355 cc, err := grpc.NewClient(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(tmr))
356 if err != nil {
357 t.Fatalf("grpc.NewClient() failed: %v", err)
358 }
359 defer cc.Close()
360
361 // Make an RPC and expect it to fail with deadline exceeded error. We use a
362 // smaller timeout to ensure that the test doesn't run very long.
363 ctx, cancel := context.WithTimeout(context.Background(), defaultTestShortTimeout)
364 defer cancel()
365 makeTestRPCAndVerifyError(ctx, t, cc, codes.Unavailable, errors.New("RLS response's target list does not contain any entries for key"))
366
367 if got, _ := tmr.Metric("grpc.lb.rls.failed_picks"); got != 1 {
368 t.Fatalf("Unexpected data for metric %v, got: %v, want: %v", "grpc.lb.rls.failed_picks", got, 1)
369 }
370 if _, ok := tmr.Metric("grpc.lb.rls.target_picks"); ok {
371 t.Fatalf("Data is present for metric %v", "grpc.lb.rls.target_picks")
372 }
373 if _, ok := tmr.Metric("grpc.lb.rls.default_target_picks"); ok {
374 t.Fatalf("Data is present for metric %v", "grpc.lb.rls.default_target_picks")
375 }
376}
377
378// Test verifies the scenario where there is a matching entry in the data cache
379// which is valid and there is no pending request. The pick is expected to be

Callers

nothing calls this directly

Calls 15

MetricMethod · 0.95
NewTestMetricsRecorderFunction · 0.92
NewClientFunction · 0.92
WithResolversFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithStatsHandlerFunction · 0.92
neverThrottlingThrottlerFunction · 0.85

Tested by

no test coverage detected