Test that when a data cache entry is evicted due to config change in cache size, the picker is updated accordingly.
(t *testing.T)
| 680 | // Test that when a data cache entry is evicted due to config change |
| 681 | // in cache size, the picker is updated accordingly. |
| 682 | func (s) TestPickerUpdateOnDataCacheSizeDecrease(t *testing.T) { |
| 683 | // Override the clientConn update hook to get notified. |
| 684 | clientConnUpdateDone := make(chan struct{}, 1) |
| 685 | origClientConnUpdateHook := clientConnUpdateHook |
| 686 | clientConnUpdateHook = func() { clientConnUpdateDone <- struct{}{} } |
| 687 | defer func() { clientConnUpdateHook = origClientConnUpdateHook }() |
| 688 | |
| 689 | // Override the cache entry size func, and always return 1. |
| 690 | origEntrySizeFunc := computeDataCacheEntrySize |
| 691 | computeDataCacheEntrySize = func(cacheKey, *cacheEntry) int64 { return 1 } |
| 692 | defer func() { computeDataCacheEntrySize = origEntrySizeFunc }() |
| 693 | |
| 694 | // Override the backoff strategy to return a large backoff which |
| 695 | // will make sure the date cache entry remains in backoff for the |
| 696 | // duration of the test. |
| 697 | origBackoffStrategy := defaultBackoffStrategy |
| 698 | defaultBackoffStrategy = &fakeBackoffStrategy{backoff: defaultTestTimeout} |
| 699 | defer func() { defaultBackoffStrategy = origBackoffStrategy }() |
| 700 | |
| 701 | // Override the minEvictionDuration to ensure that when the config update |
| 702 | // reduces the cache size, the resize operation is not stopped because |
| 703 | // we find an entry whose minExpiryDuration has not elapsed. |
| 704 | origMinEvictDuration := minEvictDuration |
| 705 | minEvictDuration = time.Duration(0) |
| 706 | defer func() { minEvictDuration = origMinEvictDuration }() |
| 707 | |
| 708 | // Register the top-level wrapping balancer which forwards calls to RLS. |
| 709 | topLevelBalancerName := t.Name() + "top-level" |
| 710 | var ccWrapper *stateCapturingCC |
| 711 | stub.Register(topLevelBalancerName, stub.BalancerFuncs{ |
| 712 | Init: func(bd *stub.BalancerData) { |
| 713 | ccWrapper = newStateCapturingCC(bd.ClientConn) |
| 714 | bd.ChildBalancer = balancer.Get(Name).Build(ccWrapper, bd.BuildOptions) |
| 715 | }, |
| 716 | ParseConfig: func(sc json.RawMessage) (serviceconfig.LoadBalancingConfig, error) { |
| 717 | parser := balancer.Get(Name).(balancer.ConfigParser) |
| 718 | return parser.ParseConfig(sc) |
| 719 | }, |
| 720 | UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error { |
| 721 | return bd.ChildBalancer.UpdateClientConnState(ccs) |
| 722 | }, |
| 723 | Close: func(bd *stub.BalancerData) { |
| 724 | bd.ChildBalancer.Close() |
| 725 | }, |
| 726 | }) |
| 727 | |
| 728 | // Start an RLS server and set the throttler to never throttle requests. |
| 729 | rlsServer, rlsReqCh := rlstest.SetupFakeRLSServer(t, nil) |
| 730 | overrideAdaptiveThrottler(t, neverThrottlingThrottler()) |
| 731 | |
| 732 | // Register an LB policy to act as the child policy for RLS LB policy. |
| 733 | childPolicyName := "test-child-policy" + t.Name() |
| 734 | e2e.RegisterRLSChildPolicy(childPolicyName, nil) |
| 735 | t.Logf("Registered child policy with name %q", childPolicyName) |
| 736 | |
| 737 | // Start a couple of test backends, and set up the fake RLS server to return |
| 738 | // these as targets in the RLS response, based on request keys. |
| 739 | // Start a couple of test backends, and set up the fake RLS server to return |
nothing calls this directly
no test coverage detected