mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Fix flaky TestPolicyWebhooks (#3777)
* Fix flaky TestPolicyWebhooks * Run test redis cleanup before running tests
This commit is contained in:
parent
47df5e83fe
commit
77c3a8a61e
2 changed files with 22 additions and 14 deletions
|
|
@ -75,20 +75,28 @@ func SetupRedis(tb testing.TB, cleanupKeyPrefix string, cluster, redir, readRepl
|
|||
_, err = conn.Do("PING")
|
||||
require.Nil(tb, err)
|
||||
|
||||
// We run a cleanup before running the tests in case a previous
|
||||
// run failed to run the cleanup (e.g. Ctrl+C while running tests).
|
||||
cleanup(tb, pool, cleanupKeyPrefix)
|
||||
|
||||
tb.Cleanup(func() {
|
||||
keys, err := redis.ScanKeys(pool, cleanupKeyPrefix+"*", 1000)
|
||||
require.NoError(tb, err)
|
||||
for _, k := range keys {
|
||||
func() {
|
||||
conn := pool.Get()
|
||||
defer conn.Close()
|
||||
if _, err := conn.Do("DEL", k); err != nil {
|
||||
require.NoError(tb, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
cleanup(tb, pool, cleanupKeyPrefix)
|
||||
pool.Close()
|
||||
})
|
||||
|
||||
return pool
|
||||
}
|
||||
|
||||
func cleanup(tb testing.TB, pool fleet.RedisPool, cleanupKeyPrefix string) {
|
||||
keys, err := redis.ScanKeys(pool, cleanupKeyPrefix+"*", 1000)
|
||||
require.NoError(tb, err)
|
||||
for _, k := range keys {
|
||||
func() {
|
||||
conn := pool.Get()
|
||||
defer conn.Close()
|
||||
if _, err := conn.Do("DEL", k); err != nil {
|
||||
require.NoError(tb, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2303,7 +2303,7 @@ func TestPolicyWebhooks(t *testing.T) {
|
|||
}},
|
||||
})
|
||||
return err == nil
|
||||
}, 5*time.Second, 250*time.Millisecond)
|
||||
}, 1*time.Minute, 250*time.Millisecond)
|
||||
require.NoError(t, err)
|
||||
|
||||
noPolicyResults := func(queries map[string]string) {
|
||||
|
|
@ -2368,7 +2368,7 @@ func TestPolicyWebhooks(t *testing.T) {
|
|||
3: {},
|
||||
})
|
||||
return err == nil
|
||||
}, 5*time.Second, 250*time.Millisecond)
|
||||
}, 1*time.Minute, 250*time.Millisecond)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Simulate webhook trigger by removing the hosts.
|
||||
|
|
@ -2408,7 +2408,7 @@ func TestPolicyWebhooks(t *testing.T) {
|
|||
3: {},
|
||||
})
|
||||
return err == nil
|
||||
}, 5*time.Second, 250*time.Millisecond)
|
||||
}, 1*time.Minute, 250*time.Millisecond)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue