Test verifies the scenario where there is a matching entry in the data cache which is stale and there is no pending request. The pick is expected to be delegated to the child policy with a proactive cache refresh.
(t *testing.T)
| 478 | // which is stale and there is no pending request. The pick is expected to be |
| 479 | // delegated to the child policy with a proactive cache refresh. |
| 480 | func (s) TestPick_DataCacheHit_NoPendingEntry_StaleEntry(t *testing.T) { |
| 481 | // We expect the same pick behavior (i.e delegated to the child policy) for |
| 482 | // a proactive refresh whether the control channel is throttled or not. |
| 483 | tests := []struct { |
| 484 | name string |
| 485 | throttled bool |
| 486 | }{ |
| 487 | { |
| 488 | name: "throttled", |
| 489 | throttled: true, |
| 490 | }, |
| 491 | { |
| 492 | name: "notThrottled", |
| 493 | throttled: false, |
| 494 | }, |
| 495 | } |
| 496 | |
| 497 | for _, test := range tests { |
| 498 | t.Run(test.name, func(t *testing.T) { |
| 499 | // Start an RLS server and setup the throttler appropriately. |
| 500 | rlsServer, rlsReqCh := rlstest.SetupFakeRLSServer(t, nil) |
| 501 | var throttler *fakeThrottler |
| 502 | firstRPCDone := grpcsync.NewEvent() |
| 503 | if test.throttled { |
| 504 | throttler = oneTimeAllowingThrottler(firstRPCDone) |
| 505 | overrideAdaptiveThrottler(t, throttler) |
| 506 | } else { |
| 507 | throttler = neverThrottlingThrottler() |
| 508 | overrideAdaptiveThrottler(t, throttler) |
| 509 | } |
| 510 | |
| 511 | // Build the RLS config without a default target. Set the stale age |
| 512 | // to a very low value to force entries to become stale quickly. |
| 513 | rlsConfig := buildBasicRLSConfigWithChildPolicy(t, t.Name(), rlsServer.Address) |
| 514 | rlsConfig.RouteLookupConfig.MaxAge = durationpb.New(time.Minute) |
| 515 | rlsConfig.RouteLookupConfig.StaleAge = durationpb.New(defaultTestShortTimeout) |
| 516 | |
| 517 | // Start a test backend, and setup the fake RLS server to return |
| 518 | // this as a target in the RLS response. |
| 519 | testBackendCh, testBackendAddress := startBackend(t) |
| 520 | rlsServer.SetResponseCallback(func(context.Context, *rlspb.RouteLookupRequest) *rlstest.RouteLookupResponse { |
| 521 | return &rlstest.RouteLookupResponse{Resp: &rlspb.RouteLookupResponse{Targets: []string{testBackendAddress}}} |
| 522 | }) |
| 523 | |
| 524 | // Register a manual resolver and push the RLS service config |
| 525 | // through it. |
| 526 | r := startManualResolverWithConfig(t, rlsConfig) |
| 527 | |
| 528 | // Create new client. |
| 529 | cc, err := grpc.NewClient(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials())) |
| 530 | if err != nil { |
| 531 | t.Fatalf("Failed to create gRPC client: %v", err) |
| 532 | } |
| 533 | defer cc.Close() |
| 534 | |
| 535 | // Make an RPC and ensure it gets routed to the test backend. |
| 536 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 537 | defer cancel() |
nothing calls this directly
no test coverage detected