From 7a68d687fa7aead173a90850817656c674d9fb2f Mon Sep 17 00:00:00 2001 From: wangyelei Date: Fri, 20 Oct 2023 14:58:55 +0800 Subject: [PATCH] chore: fix unstable test of restore controller --- controllers/dataprotection/restore_controller_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/controllers/dataprotection/restore_controller_test.go b/controllers/dataprotection/restore_controller_test.go index caccd14613a..311527fd52f 100644 --- a/controllers/dataprotection/restore_controller_test.go +++ b/controllers/dataprotection/restore_controller_test.go @@ -22,9 +22,11 @@ package dataprotection import ( "fmt" "strconv" + "strings" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/types" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" @@ -243,11 +245,17 @@ var _ = Describe("Restore Controller test", func() { By("mock jobs are completed") mockRestoreJobsCompleted(restore) + var firstJobName string Eventually(testapps.CheckObj(&testCtx, client.ObjectKeyFromObject(restore), func(g Gomega, r *dpv1alpha1.Restore) { g.Expect(r.Status.Actions.PrepareData).ShouldNot(BeEmpty()) g.Expect(r.Status.Actions.PrepareData[0].Status).Should(Equal(dpv1alpha1.RestoreActionCompleted)) + firstJobName = strings.ReplaceAll(r.Status.Actions.PrepareData[0].ObjectKey, "Job/", "") })).Should(Succeed()) + By("wait for deleted first job") + Eventually(testapps.CheckObjExists(&testCtx, + types.NamespacedName{Name: firstJobName, Namespace: testCtx.DefaultNamespace}, &batchv1.Job{}, false)).Should(Succeed()) + By("after the first job is completed, next job will be created") checkJobAndPVCSCount(restore, 1, replicas, startingIndex)