Skip to content

Commit

Permalink
Fix test conditions
Browse files Browse the repository at this point in the history
Signed-off-by: Radim Hrazdil <[email protected]>
  • Loading branch information
Radim Hrazdil committed Mar 23, 2021
1 parent ab9bc36 commit 4c4d12c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 3 additions & 3 deletions test/e2e/handler/nnce_conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ var _ = Describe("[rfe_id:3503][crit:medium][vendor:[email protected]][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
Expand All @@ -210,8 +210,8 @@ var _ = Describe("[rfe_id:3503][crit:medium][vendor:[email protected]][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")
Expand Down
10 changes: 6 additions & 4 deletions test/e2e/handler/nncp_parallel_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"fmt"
"time"

. "github.com/onsi/ginkgo"
Expand All @@ -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")
Expand All @@ -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)
})
})
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/handler/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 4c4d12c

Please sign in to comment.