From a8ab76e86f11e2ece5a3d0262313140e21db249b Mon Sep 17 00:00:00 2001 From: Nikolaus Schuetz Date: Tue, 28 Jul 2026 17:59:38 -0700 Subject: [PATCH] test(action): poll for the interrupted install goroutine instead of a zero-margin sleep (#32328) TestInstallRelease_Wait_Interrupted and TestInstallRelease_RollbackOnFailure_Interrupted assert that the detached installation goroutine has exited by sleeping a fixed 10s -- exactly the FailingKubeClient WaitDuration the goroutine blocks on. Sleeping the same duration the goroutine takes is a zero-margin race: if the goroutine finishes a hair after the fixed sleep elapses (scheduler jitter under load), getGoroutineCount() has not decremented yet and the assertion flakes. Replace the fixed sleep + point-in-time assert with is.Eventually polling getGoroutineCount() (30s ceiling, 10ms tick). It returns as soon as the goroutine has actually finished and no longer races the exact wait duration. Test-only; no change to install behavior. Signed-off-by: Nikolaus Schuetz --- pkg/action/install_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/action/install_test.go b/pkg/action/install_test.go index 80f3bd724..2d83abe27 100644 --- a/pkg/action/install_test.go +++ b/pkg/action/install_test.go @@ -653,8 +653,10 @@ func TestInstallRelease_Wait_Interrupted(t *testing.T) { req.ErrorContains(err, "context canceled") is.Equal(goroutines+1, instAction.getGoroutineCount()) // installation goroutine still is in background - time.Sleep(10 * time.Second) // wait for goroutine to finish - is.Equal(goroutines, instAction.getGoroutineCount()) + // Poll until the background installation goroutine has finished. + is.Eventually(func() bool { + return instAction.getGoroutineCount() == goroutines + }, 30*time.Second, 10*time.Millisecond) } func TestInstallRelease_WaitForJobs(t *testing.T) { @@ -754,8 +756,10 @@ func TestInstallRelease_RollbackOnFailure_Interrupted(t *testing.T) { req.Error(err) is.Equal(err, driver.ErrReleaseNotFound) is.Equal(goroutines+1, instAction.getGoroutineCount()) // installation goroutine still is in background - time.Sleep(10 * time.Second) // wait for goroutine to finish - is.Equal(goroutines, instAction.getGoroutineCount()) + // Poll until the background installation goroutine has finished. + is.Eventually(func() bool { + return instAction.getGoroutineCount() == goroutines + }, 30*time.Second, 10*time.Millisecond) } func TestNameTemplate(t *testing.T) {