From 4c4d12cce34d79a3cee5e5a46bfda8e18194eb89 Mon Sep 17 00:00:00 2001 From: Radim Hrazdil Date: Tue, 23 Mar 2021 14:05:23 +0100 Subject: [PATCH] Fix test conditions Signed-off-by: Radim Hrazdil --- test/e2e/handler/nnce_conditions_test.go | 6 +++--- test/e2e/handler/nncp_parallel_test.go | 10 ++++++---- test/e2e/handler/utils.go | 12 ++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/test/e2e/handler/nnce_conditions_test.go b/test/e2e/handler/nnce_conditions_test.go index 094c016580..fa96c82ecd 100644 --- a/test/e2e/handler/nnce_conditions_test.go +++ b/test/e2e/handler/nnce_conditions_test.go @@ -195,7 +195,7 @@ var _ = Describe("[rfe_id:3503][crit:medium][vendor:cnv-qe@redhat.com][level:com wg.Wait() }) - It("[test_id:3795] should have one Failing the rest Aborted ConditionType set to true", func() { + It("[test_id:3795] should have up to maxUnavailable Failing and the rest Aborted ConditionType set to true", func() { checkEnactmentCounts := func(policy string) { failingConditions := 0 abortedConditions := 0 @@ -210,8 +210,8 @@ var _ = Describe("[rfe_id:3503][crit:medium][vendor:cnv-qe@redhat.com][level:com abortedConditions++ } } - Expect(failingConditions).To(Equal(1), "one node only should have failing enactment") - Expect(abortedConditions).To(Equal(len(nodes)-1), "other nodes should have aborted enactment") + Expect(failingConditions).To(BeNumerically("<=", maxUnavailableNodeCount()), "one node only should have failing enactment") + Expect(abortedConditions).To(Equal(len(nodes)-failingConditions), "other nodes should have aborted enactment") } By("Check policy is at degraded state") diff --git a/test/e2e/handler/nncp_parallel_test.go b/test/e2e/handler/nncp_parallel_test.go index 701700d4f6..94784fa7a8 100644 --- a/test/e2e/handler/nncp_parallel_test.go +++ b/test/e2e/handler/nncp_parallel_test.go @@ -1,6 +1,7 @@ package handler import ( + "fmt" "time" . "github.com/onsi/ginkgo" @@ -25,6 +26,8 @@ func enactmentsInProgress(policy string) int { } var _ = Describe("NNCP with maxUnavailable", func() { + duration := 15 * time.Second + interval := 500 * time.Millisecond Context("when applying a policy to matching nodes", func() { BeforeEach(func() { By("Create a policy") @@ -40,16 +43,15 @@ var _ = Describe("NNCP with maxUnavailable", func() { }) It("should be progressing on multiple nodes", func() { Eventually(func() int { + fmt.Println(enactmentsInProgress(TestPolicy)) return enactmentsInProgress(TestPolicy) - }).Should(BeNumerically("==", maxUnavailable)) + }, duration, interval).Should(BeNumerically("==", maxUnavailableNodeCount())) waitForAvailablePolicy(TestPolicy) }) It("should never exceed maxUnavailable nodes", func() { - duration := 10 * time.Second - interval := 1 * time.Second Consistently(func() int { return enactmentsInProgress(TestPolicy) - }, duration, interval).Should(BeNumerically("<=", maxUnavailable)) + }, duration, interval).Should(BeNumerically("<=", maxUnavailableNodeCount())) waitForAvailablePolicy(TestPolicy) }) }) diff --git a/test/e2e/handler/utils.go b/test/e2e/handler/utils.go index 7240bc8715..74f5c73fa1 100644 --- a/test/e2e/handler/utils.go +++ b/test/e2e/handler/utils.go @@ -539,3 +539,15 @@ func skipIfNotKubernetes() { Skip("Tutorials use interface naming that is available only on Kubernetes providers") } } + +func maxUnavailableNodeCount() int { + intOrPercent := intstr.FromString(maxUnavailable) + maxUnavailableScaled, err := intstr.GetScaledValueFromIntOrPercent(&intOrPercent, len(allNodes), true) + if err != nil { + return 0 + } + if maxUnavailableScaled < 1 { + maxUnavailableScaled = 1 + } + return maxUnavailableScaled +}