Skip to content

Commit 4879527

Browse files
committed
Fix test race.
1 parent 5a13db4 commit 4879527

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

pkg/internal/controller/controller_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ var _ = Describe("controller", func() {
462462
// Start the sources in a goroutine
463463
startErrCh := make(chan error)
464464
go func() {
465+
defer GinkgoRecover()
465466
startErrCh <- ctrl.startEventSources(sourceCtx)
466467
}()
467468

@@ -1079,17 +1080,26 @@ var _ = Describe("controller", func() {
10791080

10801081
resultChan := make(chan bool)
10811082

1083+
// Wait for the goroutines to finish before returning to avoid racing with the
1084+
// assignment in BeforeEach block.
1085+
var wg sync.WaitGroup
1086+
10821087
// Invoked in goroutines because the Warmup / WaitForWarmupComplete will block forever.
1088+
wg.Add(2)
10831089
go func() {
1084-
err := ctrl.Warmup(ctx)
1085-
Expect(err).NotTo(HaveOccurred())
1090+
defer GinkgoRecover()
1091+
defer wg.Done()
1092+
Expect(ctrl.Warmup(ctx)).To(Succeed())
10861093
}()
10871094
go func() {
1095+
defer GinkgoRecover()
1096+
defer wg.Done()
10881097
resultChan <- ctrl.WaitForWarmupComplete(ctx)
10891098
}()
10901099

10911100
cancel()
10921101
Expect(<-resultChan).To(BeTrue())
1102+
wg.Wait()
10931103
})
10941104

10951105
It("should be called before leader election runnables if warmup is enabled", func() {

0 commit comments

Comments
 (0)