Skip to content

Commit

Permalink
add cancel context
Browse files Browse the repository at this point in the history
  • Loading branch information
linglingye001 committed Aug 20, 2024
1 parent f77d97b commit 2e096d8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ limitations under the License.
package controller

import (
"context"
"path/filepath"
"testing"
"time"

"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -48,6 +50,8 @@ var k8sClient client.Client
var testEnv *envtest.Environment
var mockCtrl *gomock.Controller
var mockConfigurationSettings *mocks.MockConfigurationSettingsRetriever
var ctx context.Context
var cancel context.CancelFunc

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
Expand All @@ -58,6 +62,8 @@ func TestAPIs(t *testing.T) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

ctx, cancel = context.WithCancel(context.TODO())

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
Expand Down Expand Up @@ -103,8 +109,12 @@ var _ = BeforeSuite(func() {

var _ = AfterSuite(func() {
By("tearing down the test environment")
cancel()
mockCtrl.Finish()
err := testEnv.Stop()

if err != nil {
time.Sleep(1 * time.Minute)
}
err = testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
})

0 comments on commit 2e096d8

Please sign in to comment.