Skip to content

Commit fd28e9c

Browse files
test(controller): fix flaky config sync gate test via cache-sync wait (#389)
The test asserted on operator's cached client without waiting for its informer cache to observe a CM created via the direct k8sClient, causing an intermittent race. Added an Eventually() wait on the same read path UpsertConfigmaps uses before asserting. Fixes #357 Signed-off-by: Mohit Yadav <ymohit799057@gmail.com> Co-authored-by: Brian Lockwood <lockwobr@gmail.com>
1 parent b62dadd commit fd28e9c

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

operator/internal/controller/skyhook_controller_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,14 @@ var _ = Describe("skyhook controller tests", func() {
18661866
Expect(k8sClient.Delete(ctx, existingCM)).To(Succeed())
18671867
})
18681868

1869+
// Wait for the reconciler's cached client (a separate client from
1870+
// k8sClient) to observe the CM before asserting on it. Without this,
1871+
// UpsertConfigmaps' r.List can race the watch and miss existingCM,
1872+
// silently taking the "create" branch instead of HandleConfigUpdates.
1873+
Eventually(func() error {
1874+
return operator.Get(ctx, client.ObjectKeyFromObject(existingCM), &corev1.ConfigMap{})
1875+
}).Should(Succeed())
1876+
18691877
shouldReturn, pendingSync, _, err := operator.validateAndUpsertSkyhookData(ctx, skyhook, clusterState)
18701878
Expect(err).ToNot(HaveOccurred())
18711879
Expect(shouldReturn).To(BeFalse(), "a deferred sync must not skip processSkyhooksPerNode")

0 commit comments

Comments
 (0)