Skip to content

Commit

Permalink
Fix test Observed Generation flakiness in KCP
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Apr 12, 2021
1 parent e4ae2ab commit d5d69e3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions controlplane/kubeadm/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ func TestReconcileUpdateObservedGeneration(t *testing.T) {
g.Expect(testEnv.Create(ctx, kcp)).To(Succeed())

// read kcp.Generation after create
errGettingObject := testEnv.Get(ctx, util.ObjectKey(kcp), kcp)
g.Expect(errGettingObject).NotTo(HaveOccurred())
g.Eventually(func() error {
return testEnv.Get(ctx, util.ObjectKey(kcp), kcp)
}, 10*time.Second).ShouldNot(HaveOccurred())
generation := kcp.Generation

// Set cluster.status.InfrastructureReady so we actually enter in the reconcile loop
Expand All @@ -172,7 +173,7 @@ func TestReconcileUpdateObservedGeneration(t *testing.T) {
g.Expect(result).To(Equal(ctrl.Result{}))

g.Eventually(func() int64 {
errGettingObject = testEnv.Get(ctx, util.ObjectKey(kcp), kcp)
errGettingObject := testEnv.Get(ctx, util.ObjectKey(kcp), kcp)
g.Expect(errGettingObject).NotTo(HaveOccurred())
return kcp.Status.ObservedGeneration
}, 10*time.Second).Should(Equal(generation))
Expand All @@ -182,8 +183,9 @@ func TestReconcileUpdateObservedGeneration(t *testing.T) {
g.Expect(testEnv.Update(ctx, kcp)).To(Succeed())

// read kcp.Generation after the update
errGettingObject = testEnv.Get(ctx, util.ObjectKey(kcp), kcp)
g.Expect(errGettingObject).NotTo(HaveOccurred())
g.Eventually(func() error {
return testEnv.Get(ctx, util.ObjectKey(kcp), kcp)
}, 10*time.Second).ShouldNot(HaveOccurred())
generation = kcp.Generation

// call reconcile the second time, so we can check if observedGeneration is set when calling defer patch
Expand All @@ -192,7 +194,7 @@ func TestReconcileUpdateObservedGeneration(t *testing.T) {
_, _ = r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(kcp)})

g.Eventually(func() int64 {
errGettingObject = testEnv.Get(ctx, util.ObjectKey(kcp), kcp)
errGettingObject := testEnv.Get(ctx, util.ObjectKey(kcp), kcp)
g.Expect(errGettingObject).NotTo(HaveOccurred())
return kcp.Status.ObservedGeneration
}, 10*time.Second).Should(Equal(generation))
Expand Down

0 comments on commit d5d69e3

Please sign in to comment.