From ab508a52d648514928f388c53ebab0ad2670ee95 Mon Sep 17 00:00:00 2001 From: Leonard Cohnen Date: Thu, 12 Jan 2023 14:11:37 +0100 Subject: [PATCH] operator: make test more resilient --- .../autoscalingstrategy_controller_env_test.go | 10 +--------- .../controllers/nodeversion_controller_env_test.go | 14 ++++++++++---- .../scalinggroup_controller_env_test.go | 12 ++---------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/operators/constellation-node-operator/controllers/autoscalingstrategy_controller_env_test.go b/operators/constellation-node-operator/controllers/autoscalingstrategy_controller_env_test.go index 039b7743d..a64988be7 100644 --- a/operators/constellation-node-operator/controllers/autoscalingstrategy_controller_env_test.go +++ b/operators/constellation-node-operator/controllers/autoscalingstrategy_controller_env_test.go @@ -32,7 +32,6 @@ var _ = Describe("AutoscalingStrategy controller", func() { ScalingGroupNameControlPlane = "control-plane-group" timeout = time.Second * 20 - duration = time.Second * 2 interval = time.Millisecond * 250 ) @@ -146,14 +145,7 @@ var _ = Describe("AutoscalingStrategy controller", func() { return -1, err } return createdStrategy.Status.Replicas, nil - }, duration, interval).Should(Equal(int32(1))) - Consistently(func() (int32, error) { - err := k8sClient.Get(ctx, strategyLookupKey, createdStrategy) - if err != nil { - return -1, err - } - return createdStrategy.Status.Replicas, nil - }, duration, interval).Should(Equal(int32(1))) + }, timeout, interval).Should(Equal(int32(1))) By("disabling the autoscaler in the strategy") Expect(k8sClient.Get(ctx, strategyLookupKey, strategy)).Should(Succeed()) diff --git a/operators/constellation-node-operator/controllers/nodeversion_controller_env_test.go b/operators/constellation-node-operator/controllers/nodeversion_controller_env_test.go index c79d49ee3..b9304df35 100644 --- a/operators/constellation-node-operator/controllers/nodeversion_controller_env_test.go +++ b/operators/constellation-node-operator/controllers/nodeversion_controller_env_test.go @@ -162,8 +162,14 @@ var _ = Describe("NodeVersion controller", func() { By("updating the node version") fakes.nodeStateGetter.setNodeState(updatev1alpha1.NodeStateReady) fakes.nodeReplacer.setCreatedNode(secondNodeName, secondNodeName, nil) - nodeVersion.Spec = newNodeVersionSpec - Expect(k8sClient.Update(ctx, nodeVersion)).Should(Succeed()) + // Eventually the node version with the new NodeVersion spec. + Eventually(func() error { + if err := k8sClient.Get(ctx, nodeVersionLookupKey, nodeVersion); err != nil { + return err + } + nodeVersion.Spec = newNodeVersionSpec + return k8sClient.Update(ctx, nodeVersion) + }, timeout, interval).Should(Succeed()) By("checking that there is an outdated node in the status") Eventually(func() int { @@ -185,11 +191,11 @@ var _ = Describe("NodeVersion controller", func() { pendingNode := &updatev1alpha1.PendingNode{} Eventually(func() error { return k8sClient.Get(ctx, joiningPendingNodeLookupKey, pendingNode) - }).Should(Succeed()) + }, timeout, interval).Should(Succeed()) Eventually(func() updatev1alpha1.CSPNodeState { _ = k8sClient.Get(ctx, joiningPendingNodeLookupKey, pendingNode) return pendingNode.Status.CSPNodeState - }).Should(Equal(updatev1alpha1.NodeStateReady)) + }, timeout, interval).Should(Equal(updatev1alpha1.NodeStateReady)) Eventually(func() int { if err := k8sClient.Get(ctx, nodeVersionLookupKey, nodeVersion); err != nil { return 0 diff --git a/operators/constellation-node-operator/controllers/scalinggroup_controller_env_test.go b/operators/constellation-node-operator/controllers/scalinggroup_controller_env_test.go index f6b287dc2..039a27424 100644 --- a/operators/constellation-node-operator/controllers/scalinggroup_controller_env_test.go +++ b/operators/constellation-node-operator/controllers/scalinggroup_controller_env_test.go @@ -27,7 +27,6 @@ var _ = Describe("ScalingGroup controller", func() { scalingGroupName = "test-group" timeout = time.Second * 20 - duration = time.Second * 2 interval = time.Millisecond * 250 ) @@ -89,13 +88,6 @@ var _ = Describe("ScalingGroup controller", func() { } return createdScalingGroup.Status.ImageReference }, timeout, interval).Should(Equal("image-1")) - Consistently(func() (string, error) { - err := k8sClient.Get(ctx, scalingGroupLookupKey, createdScalingGroup) - if err != nil { - return "", err - } - return createdScalingGroup.Status.ImageReference, nil - }, duration, interval).Should(Equal("image-1")) By("updating the node image") Expect(k8sClient.Get(ctx, nodeVersionLookupKey, nodeVersion)).Should(Succeed()) @@ -109,13 +101,13 @@ var _ = Describe("ScalingGroup controller", func() { }, timeout, interval).Should(Equal("image-2")) By("checking the scaling group status shows the latest image") - Consistently(func() (string, error) { + Eventually(func() (string, error) { err := k8sClient.Get(ctx, scalingGroupLookupKey, createdScalingGroup) if err != nil { return "", err } return createdScalingGroup.Status.ImageReference, nil - }, duration, interval).Should(Equal("image-2")) + }, timeout, interval).Should(Equal("image-2")) By("cleaning up all resources") Expect(k8sClient.Delete(ctx, createdNodeVersion)).Should(Succeed())