Skip to content

Commit 1495bba

Browse files
committed
Fix race condition in E2E test
Signed-off-by: Jonathan West <[email protected]>
1 parent 142230a commit 1495bba

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

tests/e2e/plugin_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"time"
78

89
"github.com/argoproj-labs/rollouts-plugin-trafficrouter-openshift/pkg/plugin"
910
"github.com/argoproj-labs/rollouts-plugin-trafficrouter-openshift/tests/fixtures"
@@ -248,12 +249,17 @@ var _ = Describe("OpenShift Route Traffic Plugin Tests", func() {
248249
Eventually(routeA, "20s", "1s").Should(routeFixture.HaveWeights(50, 50))
249250
Eventually(routeB, "20s", "1s").Should(routeFixture.HaveWeights(50, 50))
250251

252+
// There is a race condition in Rollouts where a call to PromoteRollout too quickly will cause 'Rollout phase mismatch, got Paused, want Healthy'
253+
// I don't see a way to know when it's possible to promote the Rollout, so for now just wait X seconds
254+
Eventually(rollout, "30s", "5s").Should(rolloutFixture.HaveExpectedObservedGeneration())
255+
time.Sleep(10 * time.Second)
256+
251257
By("promote the Rollout for the final time and verify if the previous version is removed")
252258
rollout, err = promote.PromoteRollout(rolloutClient.ArgoprojV1alpha1().Rollouts(namespace),
253259
rolloutName, false, false, false)
254260
Expect(err).ToNot(HaveOccurred())
255261

256-
Eventually(rollout, "30s", "1s").Should(rolloutFixture.HavePhase(rolloutsv1alpha1.RolloutPhaseHealthy))
262+
Eventually(rollout, "2m", "5s").Should(rolloutFixture.HavePhase(rolloutsv1alpha1.RolloutPhaseHealthy))
257263

258264
By("verify if the traffic weight is updated in the Route")
259265
Eventually(routeA, "20s", "1s").Should(routeFixture.HaveWeights(100, 0))

tests/fixtures/rollout/rollout.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,38 @@ import (
1313
"k8s.io/client-go/util/retry"
1414
)
1515

16+
func HaveExpectedObservedGeneration() matcher.GomegaMatcher {
17+
18+
return WithTransform(func(rollout *rolloutsv1alpha1.Rollout) bool {
19+
rolloutClient, err := fixtures.GetRolloutsClient()
20+
if err != nil {
21+
fmt.Println("failed to create the Rollout client", err)
22+
return false
23+
}
24+
25+
ctx := context.Background()
26+
rollout, err = rolloutClient.ArgoprojV1alpha1().Rollouts(rollout.Namespace).Get(
27+
ctx,
28+
rollout.Name,
29+
metav1.GetOptions{},
30+
)
31+
if err != nil {
32+
fmt.Println("failed to get the Rollout", err)
33+
return false
34+
}
35+
36+
generation := fmt.Sprintf("%d", rollout.Generation)
37+
observedGeneration := rollout.Status.ObservedGeneration
38+
39+
if generation != observedGeneration {
40+
fmt.Println("HaveExpectedObservedGeneration - observedGeneration does not yet match generation", generation, observedGeneration)
41+
return false
42+
}
43+
44+
return true
45+
}, BeTrue())
46+
}
47+
1648
func HavePhase(status rolloutsv1alpha1.RolloutPhase) matcher.GomegaMatcher {
1749
return WithTransform(func(rollout *rolloutsv1alpha1.Rollout) bool {
1850
rolloutClient, err := fixtures.GetRolloutsClient()
@@ -121,7 +153,7 @@ func HasTransitionedToCanary(expectedReplicas int) matcher.GomegaMatcher {
121153
return false
122154
}
123155

124-
if *rs.Spec.Replicas != int32(expectedReplicas) {
156+
if (int)(*rs.Spec.Replicas) != expectedReplicas {
125157
fmt.Printf("expected the latest ReplicaSet %s to have %d replicas", rs.Name, expectedReplicas)
126158
return false
127159
}

0 commit comments

Comments
 (0)