From fd4f0fe7a101974e30ceaf84009bc40abcb974ea Mon Sep 17 00:00:00 2001 From: Stefan Bueringer Date: Mon, 18 Aug 2025 14:54:51 +0200 Subject: [PATCH] Fix race condition in Warmup unit test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Büringer buringerst@vmware.com --- pkg/internal/controller/controller_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/internal/controller/controller_test.go b/pkg/internal/controller/controller_test.go index f30b060528..71d778c041 100644 --- a/pkg/internal/controller/controller_test.go +++ b/pkg/internal/controller/controller_test.go @@ -1403,7 +1403,8 @@ var _ = Describe("controller", func() { wg.Wait() }) - It("should not cause a data race when called concurrently with Start and only start sources once", func(ctx SpecContext) { + It("should not cause a data race when called concurrently with Start and only start sources once", func(specCtx SpecContext) { + ctx, cancel := context.WithCancel(specCtx) ctrl.CacheSyncTimeout = time.Second numWatches := 10 @@ -1417,9 +1418,11 @@ var _ = Describe("controller", func() { } By("calling Warmup and Start concurrently") + blockOnStartChan := make(chan struct{}) go func() { defer GinkgoRecover() Expect(ctrl.Start(ctx)).To(Succeed()) + close(blockOnStartChan) }() blockOnWarmupChan := make(chan struct{}) @@ -1431,6 +1434,10 @@ var _ = Describe("controller", func() { <-blockOnWarmupChan + cancel() + + <-blockOnStartChan + Expect(watchStartedCount.Load()).To(Equal(int32(numWatches)), "source should only be started once") Expect(ctrl.startWatches).To(BeNil(), "startWatches should be reset to nil after they are started") })