Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky TestAutoUpdateAgentShouldUpdate #49883

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/web/apiserver_ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
hugoShaka marked this conversation as resolved.
Show resolved Hide resolved
}

resp, err := client.NewInsecureWebClient().Do(req)
Expand Down
11 changes: 7 additions & 4 deletions lib/web/autoupdate_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand All @@ -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
hugoShaka marked this conversation as resolved.
Show resolved Hide resolved
// 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 {
Expand Down Expand Up @@ -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{
Expand Down
Loading