From 3c35e0bc77ae60e54a29d6e48c20af468735ab46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20=C5=A0imon?= Date: Wed, 25 May 2022 09:59:04 +0200 Subject: [PATCH] updated tests ID 5990 and ID 5989 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit these tests sometimes failed due to ssp cr conflict error. This patch add retry logic, which tries to update CR multiple time if error occures Signed-off-by: Karel Šimon --- tests/webhook_test.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/webhook_test.go b/tests/webhook_test.go index d50e3ec1c..c4ecf8516 100644 --- a/tests/webhook_test.go +++ b/tests/webhook_test.go @@ -2,10 +2,13 @@ package tests import ( "fmt" + "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -149,8 +152,6 @@ var _ = Describe("Validation webhook", func() { BeforeEach(func() { strategy.SkipSspUpdateTestsIfNeeded() - - foundSsp = getSsp() }) AfterEach(func() { @@ -159,15 +160,20 @@ var _ = Describe("Validation webhook", func() { Context("Placement API validation", func() { It("[test_id:5990]should succeed with valid template-validator placement fields", func() { - foundSsp.Spec.TemplateValidator.Placement = &placementAPIValidationValidPlacement - Expect(apiClient.Update(ctx, foundSsp, client.DryRunAll)).ToNot(HaveOccurred(), - "failed to update SSP CR with valid template-validator placement fields") + Eventually(func() error { + foundSsp = getSsp() + foundSsp.Spec.TemplateValidator.Placement = &placementAPIValidationValidPlacement + return apiClient.Update(ctx, foundSsp, client.DryRunAll) + }, time.Second, tenSecondTimeout).ShouldNot(HaveOccurred(), "failed to update SSP CR with valid template-validator placement fields") }) It("[test_id:5989]should fail with invalid template-validator placement fields", func() { - foundSsp.Spec.TemplateValidator.Placement = &placementAPIValidationInvalidPlacement - Expect(apiClient.Update(ctx, foundSsp, client.DryRunAll)).To(HaveOccurred(), - "SSP CR updated with invalid template-validator placement fields") + Eventually(func() v1.StatusReason { + foundSsp = getSsp() + foundSsp.Spec.TemplateValidator.Placement = &placementAPIValidationInvalidPlacement + err := apiClient.Update(ctx, foundSsp, client.DryRunAll) + return errors.ReasonForError(err) + }, time.Second, tenSecondTimeout).Should(Equal(metav1.StatusReasonInvalid), "SSP CR updated with invalid template-validator placement fields") }) }) })