From 7f8cfb8f03bff5e2dd57477e27f5a495b9d9fe4a Mon Sep 17 00:00:00 2001 From: Markus Rudy Date: Tue, 19 Dec 2023 12:06:33 +0100 Subject: [PATCH] operators: fix flaky env test --- .../pendingnode_controller_env_test.go | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/operators/constellation-node-operator/controllers/pendingnode_controller_env_test.go b/operators/constellation-node-operator/controllers/pendingnode_controller_env_test.go index d76af1bb9..da8cc0719 100644 --- a/operators/constellation-node-operator/controllers/pendingnode_controller_env_test.go +++ b/operators/constellation-node-operator/controllers/pendingnode_controller_env_test.go @@ -43,6 +43,22 @@ var _ = Describe("PendingNode controller", func() { interval = time.Millisecond * 250 ) + beGone := func() OmegaMatcher { + return MatchError(&errors.StatusError{ + ErrStatus: metav1.Status{ + Status: "Failure", + Message: `pendingnodes.update.edgeless.systems "pending-node" not found`, + Reason: "NotFound", + Details: &metav1.StatusDetails{ + Name: pendingNodeName, + Group: "update.edgeless.systems", + Kind: "pendingnodes", + }, + Code: http.StatusNotFound, + }, + }) + } + pendingNodeLookupKey := types.NamespacedName{Name: pendingNodeName} Context("When creating pending node with goal join", func() { @@ -107,27 +123,17 @@ var _ = Describe("PendingNode controller", func() { fakes.nodeStateGetter.setNodeState(updatev1alpha1.NodeStateTerminated) // trigger reconciliation before regular check interval to speed up test by changing the spec Eventually(func() error { - Expect(k8sClient.Get(ctx, pendingNodeLookupKey, pendingNode)).Should(Succeed()) + if err := k8sClient.Get(ctx, pendingNodeLookupKey, pendingNode); err != nil { + return err + } pendingNode.Spec.Deadline = &metav1.Time{Time: fakes.clock.Now().Add(time.Second)} return k8sClient.Update(ctx, pendingNode) - }, timeout, interval).Should(Succeed()) + }, timeout, interval).Should(Or(Succeed(), beGone())) By("checking if the pending node resource is deleted") Eventually(func() error { return k8sClient.Get(ctx, pendingNodeLookupKey, createdPendingNode) - }, timeout, interval).Should(MatchError(&errors.StatusError{ - ErrStatus: metav1.Status{ - Status: "Failure", - Message: `pendingnodes.update.edgeless.systems "pending-node" not found`, - Reason: "NotFound", - Details: &metav1.StatusDetails{ - Name: pendingNodeName, - Group: "update.edgeless.systems", - Kind: "pendingnodes", - }, - Code: http.StatusNotFound, - }, - })) + }, timeout, interval).Should(beGone()) }) It("Should should detect successful node join", func() {