Browse Source

Fix the test Make task (#2381)

* Fix the test Make task

Signed-off-by: shuheiktgw <s-kitagawa@mercari.com>

* fix: retry shutdown of testEnv

Signed-off-by: Moritz Johner <beller.moritz@googlemail.com>

---------

Signed-off-by: shuheiktgw <s-kitagawa@mercari.com>
Signed-off-by: Moritz Johner <beller.moritz@googlemail.com>
Co-authored-by: Moritz Johner <beller.moritz@googlemail.com>
Shuhei Kitagawa 2 years ago
parent
commit
5a6d661c9e
3 changed files with 17 additions and 4 deletions
  1. 0 2
      .github/workflows/ci.yml
  2. 3 0
      Makefile
  3. 14 2
      pkg/controllers/externalsecret/suite_test.go

+ 0 - 2
.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:

+ 3 - 0
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

+ 14 - 2
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())
 })