From ee258fd2488922c7ee8b3b7b96cc17ffdb1c6266 Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Tue, 1 Sep 2026 12:02:39 +1000 Subject: [PATCH] refactor: back the e2e Eventually helpers with testify Delegate the hand-rolled deadline loops to require.Eventually and require.EventuallyWithT instead of open-coding the polling. --- tests/e2e/harness/wait.go | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/tests/e2e/harness/wait.go b/tests/e2e/harness/wait.go index d3b3c0813..a5dcb28f2 100644 --- a/tests/e2e/harness/wait.go +++ b/tests/e2e/harness/wait.go @@ -6,44 +6,25 @@ import ( "context" "testing" "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) // Eventually polls cond until it returns true or the timeout expires. // Replaces every `sleep N; ` loop in the bash scripts. func Eventually(t *testing.T, cond func() bool, timeout, interval time.Duration, msgAndArgs ...any) { t.Helper() - deadline := time.Now().Add(timeout) - for { - if cond() { - return - } - if time.Now().After(deadline) { - if len(msgAndArgs) == 0 { - t.Fatalf("Eventually: condition not met within %s", timeout) - } - t.Fatalf("Eventually: condition not met within %s: %v", timeout, msgAndArgs) - } - time.Sleep(interval) - } + require.Eventually(t, cond, timeout, interval, msgAndArgs...) } // EventuallyErr is like Eventually but lets cond return an error for the // failure message. Useful when the probe itself yields diagnostic detail. func EventuallyErr(t *testing.T, cond func() error, timeout, interval time.Duration) { t.Helper() - deadline := time.Now().Add(timeout) - var lastErr error - for { - if err := cond(); err == nil { - return - } else { - lastErr = err - } - if time.Now().After(deadline) { - t.Fatalf("EventuallyErr: condition not met within %s: %v", timeout, lastErr) - } - time.Sleep(interval) - } + require.EventuallyWithT(t, func(c *assert.CollectT) { + assert.NoError(c, cond()) + }, timeout, interval) } // RetryWithReset runs fn as "attempt-1"; on failure it calls ResetAllNodes and