From cad37eb9f640e94c6c524e717939ef7463fac531 Mon Sep 17 00:00:00 2001 From: Aitor Perez Cedres Date: Tue, 12 Dec 2023 12:34:39 +0000 Subject: [PATCH] Run integration tests in parallel Execution time has cut down from 10 minutes to 1 minute and a few seconds (!!!) The solution is to start an API server for each parallel process, listening on different ports. I tried to start only one API server and share the API information among other parallel processes, but it was not possible because the testEnv Environment does not implement any of the marshall interfaces, so it is not possible to binary encode it. Binary encoding is the method that Ginkgo uses to share information between processes in the Synchronized Before/After suites. Signed-off-by: Aitor Perez Cedres --- Makefile | 6 +++--- controllers/suite_test.go | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c3c2fcba..aec426c9 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ install-tools: go install golang.org/x/vuln/cmd/govulncheck@latest ENVTEST_K8S_VERSION = 1.26.1 -ARCHITECTURE = amd64 +ARCHITECTURE = $(shell go env GOARCH) LOCAL_TESTBIN = $(CURDIR)/testbin LOCAL_BIN := $(CURDIR)/bin @@ -55,10 +55,10 @@ unit-tests: install-tools $(KUBEBUILDER_ASSETS) generate fmt vet manifests ## Ru .PHONY: integration-tests integration-tests: install-tools $(KUBEBUILDER_ASSETS) generate fmt vet manifests ## Run integration tests - ginkgo -r --randomize-all controllers/ + ginkgo -r --randomize-all -p controllers/ just-integration-tests: $(KUBEBUILDER_ASSETS) vet - ginkgo --randomize-all -r controllers/ + ginkgo --randomize-all -r -p controllers/ local-tests: unit-tests integration-tests ## Run all local tests (unit & integration) diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 04cf9bef..114a9b38 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -15,6 +15,7 @@ import ( "fmt" "go/build" "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" "path/filepath" "testing" "time" @@ -101,6 +102,9 @@ var _ = BeforeSuite(func() { filepath.Join(build.Default.GOPATH, "pkg", "mod", "github.com", "rabbitmq", "cluster-operator", "v2@v2.6.0", "config", "crd", "bases"), }, ErrorIfCRDPathMissing: true, + Config: &rest.Config{ + Host: fmt.Sprintf("localhost:818%d", GinkgoParallelProcess()), + }, } cfg, err := testEnv.Start()