TestConfigUpdate_DataCacheSizeDecrease tests the scenario where a config update decreases the data cache size. Verifies that entries are evicted from the cache.
(t *testing.T)
| 561 | // update decreases the data cache size. Verifies that entries are evicted from |
| 562 | // the cache. |
| 563 | func (s) TestConfigUpdate_DataCacheSizeDecrease(t *testing.T) { |
| 564 | // Override the clientConn update hook to get notified. |
| 565 | clientConnUpdateDone := make(chan struct{}, 1) |
| 566 | origClientConnUpdateHook := clientConnUpdateHook |
| 567 | clientConnUpdateHook = func() { clientConnUpdateDone <- struct{}{} } |
| 568 | defer func() { clientConnUpdateHook = origClientConnUpdateHook }() |
| 569 | |
| 570 | // Override the cache entry size func, and always return 1. |
| 571 | origEntrySizeFunc := computeDataCacheEntrySize |
| 572 | computeDataCacheEntrySize = func(cacheKey, *cacheEntry) int64 { return 1 } |
| 573 | defer func() { computeDataCacheEntrySize = origEntrySizeFunc }() |
| 574 | |
| 575 | // Override the minEvictionDuration to ensure that when the config update |
| 576 | // reduces the cache size, the resize operation is not stopped because |
| 577 | // we find an entry whose minExpiryDuration has not elapsed. |
| 578 | origMinEvictDuration := minEvictDuration |
| 579 | minEvictDuration = time.Duration(0) |
| 580 | defer func() { minEvictDuration = origMinEvictDuration }() |
| 581 | |
| 582 | // Start an RLS server and set the throttler to never throttle requests. |
| 583 | rlsServer, rlsReqCh := rlstest.SetupFakeRLSServer(t, nil) |
| 584 | overrideAdaptiveThrottler(t, neverThrottlingThrottler()) |
| 585 | |
| 586 | // Register an LB policy to act as the child policy for RLS LB policy. |
| 587 | childPolicyName := "test-child-policy" + t.Name() |
| 588 | e2e.RegisterRLSChildPolicy(childPolicyName, nil) |
| 589 | t.Logf("Registered child policy with name %q", childPolicyName) |
| 590 | |
| 591 | // Build RLS service config with header matchers. |
| 592 | rlsConfig := buildBasicRLSConfig(childPolicyName, rlsServer.Address) |
| 593 | |
| 594 | // Start a couple of test backends, and set up the fake RLS server to return |
| 595 | // these as targets in the RLS response, based on request keys. |
| 596 | backendCh1, backendAddress1 := startBackend(t) |
| 597 | backendCh2, backendAddress2 := startBackend(t) |
| 598 | rlsServer.SetResponseCallback(func(_ context.Context, req *rlspb.RouteLookupRequest) *rlstest.RouteLookupResponse { |
| 599 | if req.KeyMap["k1"] == "v1" { |
| 600 | return &rlstest.RouteLookupResponse{Resp: &rlspb.RouteLookupResponse{Targets: []string{backendAddress1}}} |
| 601 | } |
| 602 | if req.KeyMap["k2"] == "v2" { |
| 603 | return &rlstest.RouteLookupResponse{Resp: &rlspb.RouteLookupResponse{Targets: []string{backendAddress2}}} |
| 604 | } |
| 605 | return &rlstest.RouteLookupResponse{Err: errors.New("no keys in request metadata")} |
| 606 | }) |
| 607 | |
| 608 | // Register a manual resolver and push the RLS service config through it. |
| 609 | r := startManualResolverWithConfig(t, rlsConfig) |
| 610 | |
| 611 | cc, err := grpc.NewClient(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials())) |
| 612 | if err != nil { |
| 613 | t.Fatalf("grpc.NewClient() failed: %v", err) |
| 614 | } |
| 615 | defer cc.Close() |
| 616 | cc.Connect() |
| 617 | |
| 618 | <-clientConnUpdateDone |
| 619 | |
| 620 | // Make an RPC and ensure it gets routed to the first backend. |
nothing calls this directly
no test coverage detected