Skip to content

Commit f4303b0

Browse files
authored
Merge pull request #3287 from sbueringer/pr-fix-race
🐛 Fix race condition in Warmup unit test
2 parents 3554729 + fd4f0fe commit f4303b0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/internal/controller/controller_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,8 @@ var _ = Describe("controller", func() {
14031403
wg.Wait()
14041404
})
14051405

1406-
It("should not cause a data race when called concurrently with Start and only start sources once", func(ctx SpecContext) {
1406+
It("should not cause a data race when called concurrently with Start and only start sources once", func(specCtx SpecContext) {
1407+
ctx, cancel := context.WithCancel(specCtx)
14071408

14081409
ctrl.CacheSyncTimeout = time.Second
14091410
numWatches := 10
@@ -1417,9 +1418,11 @@ var _ = Describe("controller", func() {
14171418
}
14181419

14191420
By("calling Warmup and Start concurrently")
1421+
blockOnStartChan := make(chan struct{})
14201422
go func() {
14211423
defer GinkgoRecover()
14221424
Expect(ctrl.Start(ctx)).To(Succeed())
1425+
close(blockOnStartChan)
14231426
}()
14241427

14251428
blockOnWarmupChan := make(chan struct{})
@@ -1431,6 +1434,10 @@ var _ = Describe("controller", func() {
14311434

14321435
<-blockOnWarmupChan
14331436

1437+
cancel()
1438+
1439+
<-blockOnStartChan
1440+
14341441
Expect(watchStartedCount.Load()).To(Equal(int32(numWatches)), "source should only be started once")
14351442
Expect(ctrl.startWatches).To(BeNil(), "startWatches should be reset to nil after they are started")
14361443
})

0 commit comments

Comments
 (0)