diff --git a/pkg/kubelet/kuberuntime/kuberuntime_termination_order_test.go b/pkg/kubelet/kuberuntime/kuberuntime_termination_order_test.go index 67a93d8ac34..a183d6bcb25 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_termination_order_test.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_termination_order_test.go @@ -55,9 +55,11 @@ func TestTerminationOrderingSidecarStopAfterMain(t *testing.T) { var wg sync.WaitGroup wg.Add(1) - var sidecarWaitDelay int64 - var mainWaitDelay int64 + var sidecarWaitDelay, mainWaitDelay int64 + syncChannel := make(chan struct{}) + go func() { + close(syncChannel) // notifies other goroutine that this goroutine scheduled. sidecarWaitDelay = int64(to.waitForTurn("init", 30)) to.containerTerminated("init") wg.Done() @@ -65,6 +67,7 @@ func TestTerminationOrderingSidecarStopAfterMain(t *testing.T) { wg.Add(1) go func() { + <-syncChannel // make sure the other goroutine is scheduled. mainWaitDelay = int64(to.waitForTurn("main", 0)) time.Sleep(1 * time.Second) to.containerTerminated("main")