From f34ef4e1f787ab1ab2513cc8cf6c5ac6ec1c5e7d Mon Sep 17 00:00:00 2001 From: Etienne Perot Date: Tue, 17 Dec 2024 21:15:53 -0800 Subject: [PATCH] `testcluster`: Handle short-lived pods in `WaitForPodRunning`. Prior to this change, `WaitForPodRunning` was susceptible to a race condition whereby a short-lived pod could run and complete before the poll loop notices that its state has changed to "running". PiperOrigin-RevId: 707380314 --- test/kubernetes/testcluster/testcluster.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/kubernetes/testcluster/testcluster.go b/test/kubernetes/testcluster/testcluster.go index 4342384d7..0e824fc2f 100644 --- a/test/kubernetes/testcluster/testcluster.go +++ b/test/kubernetes/testcluster/testcluster.go @@ -451,7 +451,9 @@ func (t *TestCluster) ReadPodLogs(ctx context.Context, pod *v13.Pod) (string, er // WaitForPodRunning is a helper method to wait for a pod to be running. func (t *TestCluster) WaitForPodRunning(ctx context.Context, pod *v13.Pod) error { - _, err := t.doWaitForPod(ctx, pod, func(p v13.PodPhase) bool { return p == v13.PodRunning }) + // We also accept pods in the PodSucceeded state, because short-lived pods + // may have already ran and succeeded by the time we poll them. + _, err := t.doWaitForPod(ctx, pod, func(p v13.PodPhase) bool { return p == v13.PodRunning || p == v13.PodSucceeded }) return err }