Skip to content

Commit

Permalink
Fix flaky TestAutoUpdateAgentShouldUpdate (#49883)
Browse files Browse the repository at this point in the history
* Fix flaky TestAutoUpdateAgentShouldUpdate

* Update lib/web/apiserver_ping_test.go

* Update lib/web/autoupdate_common_test.go
  • Loading branch information
hugoShaka authored Dec 6, 2024
1 parent 460ac5e commit 3e3e464
Showing 1 changed file with 7 additions and 4 deletions.
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 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())}
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

0 comments on commit 3e3e464

Please sign in to comment.