Skip to content

🐛 Fix race condition in Warmup unit test #3287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/internal/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{})
Expand All @@ -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")
})
Expand Down