From 6d9eff9f102843805d5165fb5cf1d99f56ba321c Mon Sep 17 00:00:00 2001 From: hugoShaka Date: Fri, 6 Dec 2024 10:58:01 -0500 Subject: [PATCH 1/3] Fix flaky TestAutoUpdateAgentShouldUpdate --- lib/web/apiserver_ping_test.go | 1 + lib/web/autoupdate_common_test.go | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/web/apiserver_ping_test.go b/lib/web/apiserver_ping_test.go index 84e073ca7ae87..87c44cc67712c 100644 --- a/lib/web/apiserver_ping_test.go +++ b/lib/web/apiserver_ping_test.go @@ -459,6 +459,7 @@ func TestPing_autoUpdateResources(t *testing.T) { // expire the fn cache to force the next answer to be fresh for _, proxy := range env.proxies { proxy.clock.Advance(2 * findEndpointCacheTTL) + proxy.handler.handler.findEndpointCache.RemoveExpired() } resp, err := client.NewInsecureWebClient().Do(req) diff --git a/lib/web/autoupdate_common_test.go b/lib/web/autoupdate_common_test.go index a365ac121b078..f8039ee58f59f 100644 --- a/lib/web/autoupdate_common_test.go +++ b/lib/web/autoupdate_common_test.go @@ -167,10 +167,10 @@ func TestAutoUpdateAgentShouldUpdate(t *testing.T) { })) t.Cleanup(brokenChannelUpstream.Close) - clock := clockwork.NewFakeClock() + cacheClock := clockwork.NewFakeClock() cmcCache, err := utils.NewFnCache(utils.FnCacheConfig{ TTL: findEndpointCacheTTL, - Clock: clock, + Clock: cacheClock, Context: ctx, ReloadOnErr: false, }) @@ -179,6 +179,9 @@ func TestAutoUpdateAgentShouldUpdate(t *testing.T) { cmcCache.Shutdown(ctx) }) + // We use a separate clock than the cache because we are advancing the cache clock to invalidate the cmc cache and + // this would interfere with the test logic + clock := clockwork.NewFakeClock() activeUpgradeWindow := types.AgentUpgradeWindow{UTCStartHour: uint32(clock.Now().Hour())} inactiveUpgradeWindow := types.AgentUpgradeWindow{UTCStartHour: uint32(clock.Now().Add(2 * time.Hour).Hour())} tests := []struct { @@ -321,8 +324,8 @@ func TestAutoUpdateAgentShouldUpdate(t *testing.T) { cmc := types.NewClusterMaintenanceConfig() cmc.SetAgentUpgradeWindow(tt.upgradeWindow) require.NoError(t, tt.channel.CheckAndSetDefaults()) - // Advance clock to invalidate cache - clock.Advance(2 * findEndpointCacheTTL) + // Advance cache clock to expire cached cmc + cacheClock.Advance(2 * findEndpointCacheTTL) h := &Handler{ cfg: Config{ AccessPoint: &fakeRolloutAccessPoint{ From 9b73323412ed0f2d5b0d29592075947a2c3c1b71 Mon Sep 17 00:00:00 2001 From: Hugo Shaka Date: Fri, 6 Dec 2024 11:24:27 -0500 Subject: [PATCH 2/3] Update lib/web/apiserver_ping_test.go --- lib/web/apiserver_ping_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/web/apiserver_ping_test.go b/lib/web/apiserver_ping_test.go index 87c44cc67712c..84e073ca7ae87 100644 --- a/lib/web/apiserver_ping_test.go +++ b/lib/web/apiserver_ping_test.go @@ -459,7 +459,6 @@ func TestPing_autoUpdateResources(t *testing.T) { // expire the fn cache to force the next answer to be fresh for _, proxy := range env.proxies { proxy.clock.Advance(2 * findEndpointCacheTTL) - proxy.handler.handler.findEndpointCache.RemoveExpired() } resp, err := client.NewInsecureWebClient().Do(req) From 03b88d410cc61ac2e093a0c00af6fdb66faf2255 Mon Sep 17 00:00:00 2001 From: Hugo Shaka Date: Fri, 6 Dec 2024 11:25:57 -0500 Subject: [PATCH 3/3] Update lib/web/autoupdate_common_test.go --- lib/web/autoupdate_common_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web/autoupdate_common_test.go b/lib/web/autoupdate_common_test.go index f8039ee58f59f..e0a1a31719586 100644 --- a/lib/web/autoupdate_common_test.go +++ b/lib/web/autoupdate_common_test.go @@ -179,7 +179,7 @@ func TestAutoUpdateAgentShouldUpdate(t *testing.T) { cmcCache.Shutdown(ctx) }) - // We use a separate clock than the cache because we are advancing the cache clock to invalidate the cmc cache and + // We don't use the cache clock because we are advancing it to invalidate the cmc cache and // this would interfere with the test logic clock := clockwork.NewFakeClock() activeUpgradeWindow := types.AgentUpgradeWindow{UTCStartHour: uint32(clock.Now().Hour())}