From c1a61b9e34c5c370a1f74e201c5004e2526d710d Mon Sep 17 00:00:00 2001 From: Johan Brandhorst-Satzkorn Date: Wed, 5 Apr 2023 15:45:52 -0700 Subject: [PATCH] internal/tests/cluster: switch flaky test to polling (#3153) * internal/tests/cluster: switch flaky test to polling Also extend deadline from 10 seconds to 1 minute, hopefully this should fix any flakiness in this test. * fixup! internal/tests/cluster: switch flaky test to polling --- .../tests/cluster/switch_kms_method_test.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/tests/cluster/switch_kms_method_test.go b/internal/tests/cluster/switch_kms_method_test.go index 037490e25f..600dfee58c 100644 --- a/internal/tests/cluster/switch_kms_method_test.go +++ b/internal/tests/cluster/switch_kms_method_test.go @@ -4,6 +4,7 @@ package cluster import ( + "context" "os" "strings" "sync" @@ -74,8 +75,22 @@ func TestWorkerUpgradeKmsAuthMethod(t *testing.T) { }) defer w1.Shutdown() - // Give time for it to connect - time.Sleep(10 * time.Second) + timeout := time.Minute + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + for { + logBuf, err = os.ReadFile(ec.AllEvents.Name()) + require.NoError(t, err) + if strings.Count(string(logBuf), "worker has successfully authenticated") == 2 { + break + } + select { + case <-ctx.Done(): + t.Fatal("worker had not successfully connected after ", timeout.String()) + case <-time.After(time.Second): + // Try again + } + } // We should find only one nonce, and one successful worker authentication, // both in the output and in the database