From 5a6d661c9ebca71f3d4978df243763a5715b9c8d Mon Sep 17 00:00:00 2001 From: Shuhei Kitagawa Date: Tue, 6 Jun 2023 18:25:51 +0900 Subject: [PATCH] Fix the test Make task (#2381) * Fix the test Make task Signed-off-by: shuheiktgw * fix: retry shutdown of testEnv Signed-off-by: Moritz Johner --------- Signed-off-by: shuheiktgw Signed-off-by: Moritz Johner Co-authored-by: Moritz Johner --- .github/workflows/ci.yml | 2 -- Makefile | 3 +++ pkg/controllers/externalsecret/suite_test.go | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ced77de46..23a03053e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -161,8 +161,6 @@ jobs: - name: Run Unit Tests run: | - export KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT=true - source <(setup-envtest use ${{env.KUBERNETES_VERSION}} -p env --os $(go env GOOS) --arch $(go env GOARCH)) make test publish-artifacts: diff --git a/Makefile b/Makefile index 17a6de674..20cd554a8 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,8 @@ else GOBIN=$(shell go env GOBIN) endif +KUBERNETES_VERSION := '1.24.x' + # check if there are any existing `git tag` values ifeq ($(shell git tag),) # no tags found - default to initial tag `v0.0.0` @@ -91,6 +93,7 @@ update-deps: # Golang .PHONY: test +test: export KUBEBUILDER_ASSETS := $(shell setup-envtest use $(KUBERNETES_VERSION) -p path --os $(shell go env GOOS) --arch $(shell go env GOARCH)) test: generate ## Run tests @$(INFO) go test unit-tests go test -race -v $(shell go list ./... | grep -v e2e) -coverprofile cover.out diff --git a/pkg/controllers/externalsecret/suite_test.go b/pkg/controllers/externalsecret/suite_test.go index a6c0ee78f..0176b5da9 100644 --- a/pkg/controllers/externalsecret/suite_test.go +++ b/pkg/controllers/externalsecret/suite_test.go @@ -106,6 +106,18 @@ var _ = BeforeSuite(func() { var _ = AfterSuite(func() { By("tearing down the test environment") cancel() // stop manager - err := testEnv.Stop() - Expect(err).ToNot(HaveOccurred()) + err := (func() (err error) { + // Need to sleep if the first stop fails due to a bug: + // https://github.com/kubernetes-sigs/controller-runtime/issues/1571 + sleepTime := 1 * time.Millisecond + for i := 0; i < 12; i++ { // Exponentially sleep up to ~4s + if err = testEnv.Stop(); err == nil { + return + } + sleepTime *= 2 + time.Sleep(sleepTime) + } + return + })() + Expect(err).NotTo(HaveOccurred()) })