Skip to content
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

Remove race condition in templated test code "StartTestManager" function. #571

Closed
shaneutt opened this issue Jan 18, 2019 · 0 comments · Fixed by #572
Closed

Remove race condition in templated test code "StartTestManager" function. #571

shaneutt opened this issue Jan 18, 2019 · 0 comments · Fixed by #572

Comments

@shaneutt
Copy link
Member

shaneutt commented Jan 18, 2019

Hello! When working with kubebuilder it was noticed that the templated testing code provided for a new project technically has a race condition in it, specifically it appears to be the StartTestManager function in pkg/scaffold/controller/controllersuitetest.go.

Here's a diff of my suggestion for a fix for this:

diff --git a/pkg/scaffold/controller/controllersuitetest.go b/pkg/scaffold/controller/controllersuitetest.go
index bbdfff7c..37001ca2 100644
--- a/pkg/scaffold/controller/controllersuitetest.go
+++ b/pkg/scaffold/controller/controllersuitetest.go
@@ -96,10 +96,10 @@ func SetupTestReconcile(inner reconcile.Reconciler) (reconcile.Reconciler, chan
 func StartTestManager(mgr manager.Manager, g *gomega.GomegaWithT) (chan struct{}, *sync.WaitGroup) {
        stop := make(chan struct{})
        wg := &sync.WaitGroup{}
+       wg.Add(1)
        go func() {
-               wg.Add(1)
+               defer wg.Done()
                g.Expect(mgr.Start(stop)).NotTo(gomega.HaveOccurred())
-               wg.Done()
        }()
        return stop, wg
 }

Here is a PR for this: #572

Thank you! 👍

@shaneutt shaneutt changed the title Remove race condition in templated Remove race condition in templated test code Jan 18, 2019
@shaneutt shaneutt changed the title Remove race condition in templated test code Remove race condition in templated test code "StartTestManager" function. Jan 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant