From 9bd37415fb7bec3becc45e0afb2df90a26694057 Mon Sep 17 00:00:00 2001 From: Jiri Danek Date: Sun, 17 Nov 2024 21:05:57 +0100 Subject: [PATCH] RHOAIENG-15772: tests(odh-nbc): wait for controller manager to stop before stopping envtest Otherwise, there will be some errors printed in the output. It was not breaking anything, but it was unpleasant to look at. The notebook-controller does not seem to be suffering from this. Probably because it does not use a webhook. Example of the error message that's prevented by this ``` 2024-11-17T20:19:57+01:00 ERROR controller-runtime.certwatcher error re-reading certificate {"error": "open /var/folders/f1/3m518k5d34l72v_9nqyjzqm80000gn/T/envtest-serving-certs-737480808/tls.crt: no such file or directory"} ``` --- .../controllers/suite_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/components/odh-notebook-controller/controllers/suite_test.go b/components/odh-notebook-controller/controllers/suite_test.go index 16efc780537..b372553de4d 100644 --- a/components/odh-notebook-controller/controllers/suite_test.go +++ b/components/odh-notebook-controller/controllers/suite_test.go @@ -55,11 +55,14 @@ import ( // +kubebuilder:docs-gen:collapse=Imports var ( - cfg *rest.Config - cli client.Client - envTest *envtest.Environment + cfg *rest.Config + cli client.Client + envTest *envtest.Environment + ctx context.Context cancel context.CancelFunc + managerStopped = make(chan struct{}) + testNamespaces = []string{} ) @@ -74,7 +77,7 @@ func TestAPIs(t *testing.T) { } var _ = BeforeSuite(func() { - ctx, cancel = context.WithCancel(context.TODO()) + ctx, cancel = context.WithCancel(context.Background()) // Initialize logger opts := zap.Options{ @@ -156,6 +159,7 @@ var _ = BeforeSuite(func() { go func() { defer GinkgoRecover() err = mgr.Start(ctx) + managerStopped <- struct{}{} Expect(err).ToNot(HaveOccurred(), "Failed to run manager") }() @@ -187,7 +191,10 @@ var _ = BeforeSuite(func() { }, 60) var _ = AfterSuite(func() { + By("Stopping the manager") cancel() + <-managerStopped // Issue#429: waiting to avoid shutdown errors being logged + By("Tearing down the test environment") // TODO: Stop cert controller-runtime.certwatcher before manager err := envTest.Stop()