From 4c1e71fa0b3d33754f4d906caa86ba9f73ebafb3 Mon Sep 17 00:00:00 2001 From: Oleg Zaytsev Date: Fri, 14 Jun 2024 15:02:46 +0200 Subject: [PATCH] Reduce the flakiness of TestAsyncRuleEvaluation (#14300) * Reduce the flakiness of TestAsyncRuleEvaluation This tests sleeps for 15 millisecond per rule group, and then comprares the entire execution time to be smaller than a multiple of that delay. The ruleCount is 6, so it assumes that the test will come to the assertions in less than 90ms. Meanwhile, the Github's Windows runner: - ...Huh, oh? What? How much time? milliwhat? Sorry I don't speak that. TL;DR, this increases the delay to 250 millisecond. This won't prevent the test from being flaky, but will reduce the flakiness by several orders of magnitude and hopefully won't be an issue anymore. Signed-off-by: Oleg Zaytsev * Make tests parallel Signed-off-by: Oleg Zaytsev --------- Signed-off-by: Oleg Zaytsev --- rules/manager_test.go | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/rules/manager_test.go b/rules/manager_test.go index 11d1282bd..d31bfc07a 100644 --- a/rules/manager_test.go +++ b/rules/manager_test.go @@ -1910,18 +1910,12 @@ func TestDependencyMapUpdatesOnGroupUpdate(t *testing.T) { } func TestAsyncRuleEvaluation(t *testing.T) { - storage := teststorage.New(t) - t.Cleanup(func() { storage.Close() }) - - var ( - inflightQueries atomic.Int32 - maxInflight atomic.Int32 - ) - t.Run("synchronous evaluation with independent rules", func(t *testing.T) { - // Reset. - inflightQueries.Store(0) - maxInflight.Store(0) + t.Parallel() + storage := teststorage.New(t) + t.Cleanup(func() { storage.Close() }) + inflightQueries := atomic.Int32{} + maxInflight := atomic.Int32{} ctx, cancel := context.WithCancel(context.Background()) t.Cleanup(cancel) @@ -1949,9 +1943,11 @@ func TestAsyncRuleEvaluation(t *testing.T) { }) t.Run("asynchronous evaluation with independent and dependent rules", func(t *testing.T) { - // Reset. - inflightQueries.Store(0) - maxInflight.Store(0) + t.Parallel() + storage := teststorage.New(t) + t.Cleanup(func() { storage.Close() }) + inflightQueries := atomic.Int32{} + maxInflight := atomic.Int32{} ctx, cancel := context.WithCancel(context.Background()) t.Cleanup(cancel) @@ -1985,9 +1981,11 @@ func TestAsyncRuleEvaluation(t *testing.T) { }) t.Run("asynchronous evaluation of all independent rules, insufficient concurrency", func(t *testing.T) { - // Reset. - inflightQueries.Store(0) - maxInflight.Store(0) + t.Parallel() + storage := teststorage.New(t) + t.Cleanup(func() { storage.Close() }) + inflightQueries := atomic.Int32{} + maxInflight := atomic.Int32{} ctx, cancel := context.WithCancel(context.Background()) t.Cleanup(cancel) @@ -2021,9 +2019,11 @@ func TestAsyncRuleEvaluation(t *testing.T) { }) t.Run("asynchronous evaluation of all independent rules, sufficient concurrency", func(t *testing.T) { - // Reset. - inflightQueries.Store(0) - maxInflight.Store(0) + t.Parallel() + storage := teststorage.New(t) + t.Cleanup(func() { storage.Close() }) + inflightQueries := atomic.Int32{} + maxInflight := atomic.Int32{} ctx, cancel := context.WithCancel(context.Background()) t.Cleanup(cancel) @@ -2098,7 +2098,7 @@ func TestBoundedRuleEvalConcurrency(t *testing.T) { require.EqualValues(t, maxInflight.Load(), int32(maxConcurrency)+int32(groupCount)) } -const artificialDelay = 15 * time.Millisecond +const artificialDelay = 250 * time.Millisecond func optsFactory(storage storage.Storage, maxInflight, inflightQueries *atomic.Int32, maxConcurrent int64) *ManagerOptions { var inflightMu sync.Mutex