From 4aac52bced652ee86f526a5aeecc350c08d691db Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Mon, 22 Mar 2021 23:11:50 +0530 Subject: [PATCH] Makefile: Refactor test-server-race (#17196) test-server-race wasn't using the same set of steps that the test-server step did. Therefore one test was failing. Refactored it such that scripts/test.sh can be used to run normal and race tests as well ```release-note NONE ``` --- Makefile | 52 +++++++++++++++---------------------------------- scripts/test.sh | 6 +++++- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index f07831a097..e48ed8343a 100644 --- a/Makefile +++ b/Makefile @@ -307,39 +307,6 @@ endif check-style: golangci-lint plugin-checker vet ## Runs golangci against all packages -test-te-race: ## Checks for race conditions in the team edition. - @echo Testing TE race conditions - - @echo "Packages to test: "$(TE_PACKAGES) - - @for package in $(TE_PACKAGES); do \ - echo "Testing "$$package; \ - $(GO) test $(GOFLAGS) -race -run=$(TESTS) -test.timeout=4000s $$package || exit 1; \ - done - -test-ee-race: check-prereqs-enterprise ## Checks for race conditions in the enterprise edition. - @echo Testing EE race conditions - -ifeq ($(BUILD_ENTERPRISE_READY),true) - @echo "Packages to test: "$(EE_PACKAGES) - - for package in $(EE_PACKAGES); do \ - echo "Testing "$$package; \ - $(GO) test $(GOFLAGS) -race -run=$(TESTS) -c $$package; \ - if [ -f $$(basename $$package).test ]; then \ - echo "Testing "$$package; \ - ./$$(basename $$package).test -test.timeout=2000s || exit 1; \ - rm -r $$(basename $$package).test; \ - fi; \ - done - - rm -f config/*.crt - rm -f config/*.key -endif - -test-server-race: test-te-race test-ee-race ## Checks for race conditions. - find . -type d -name data -not -path './vendor/*' | xargs rm -rf - do-cover-file: ## Creates the test coverage report file. @echo "mode: count" > cover.out @@ -368,13 +335,26 @@ gomodtidy: fi; @rm go.*.orig; -test-server: check-prereqs-enterprise start-docker-check start-docker go-junit-report do-cover-file ## Runs tests. +test-server-pre: check-prereqs-enterprise start-docker-check start-docker go-junit-report do-cover-file ## Runs tests. ifeq ($(BUILD_ENTERPRISE_READY),true) @echo Running all tests else @echo Running only TE tests endif - ./scripts/test.sh "$(GO)" "$(GOFLAGS)" "$(ALL_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)" "$(GOBIN)" + +test-server-race: test-server-pre + ./scripts/test.sh "$(GO)" "-race $(GOFLAGS)" "$(ALL_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)" "$(GOBIN)" "90m" "atomic" + ifneq ($(IS_CI),true) + ifneq ($(MM_NO_DOCKER),true) + ifneq ($(TEMP_DOCKER_SERVICES),) + @echo Stopping temporary docker services + docker-compose stop $(TEMP_DOCKER_SERVICES) + endif + endif + endif + +test-server: test-server-pre + ./scripts/test.sh "$(GO)" "$(GOFLAGS)" "$(ALL_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)" "$(GOBIN)" "20m" "count" ifneq ($(IS_CI),true) ifneq ($(MM_NO_DOCKER),true) ifneq ($(TEMP_DOCKER_SERVICES),) @@ -386,7 +366,7 @@ endif test-server-ee: check-prereqs-enterprise start-docker-check start-docker go-junit-report do-cover-file ## Runs EE tests. @echo Running only EE tests - ./scripts/test.sh "$(GO)" "$(GOFLAGS)" "$(EE_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)" "$(GOBIN)" + ./scripts/test.sh "$(GO)" "$(GOFLAGS)" "$(EE_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)" "$(GOBIN)" "20m" "count" test-server-quick: check-prereqs-enterprise ## Runs only quick tests. ifeq ($(BUILD_ENTERPRISE_READY),true) diff --git a/scripts/test.sh b/scripts/test.sh index 32251e9005..b05650f2bd 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -9,14 +9,18 @@ PACKAGES=$3 TESTS=$4 TESTFLAGS=$5 GOBIN=$6 +TIMEOUT=$7 +COVERMODE=$8 PACKAGES_COMMA=$(echo $PACKAGES | tr ' ' ',') echo "Packages to test: $PACKAGES" +echo "GOFLAGS: $GOFLAGS" + find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \; find . -type d -name data -not -path './vendor/*' -not -path './data' | xargs rm -rf -$GO test $GOFLAGS -run=$TESTS $TESTFLAGS -v -timeout=20m -covermode=count -coverpkg=$PACKAGES_COMMA -exec $DIR/test-xprog.sh $PACKAGES 2>&1 > >( tee output ) +$GO test $GOFLAGS -run=$TESTS $TESTFLAGS -v -timeout=$TIMEOUT -covermode=$COVERMODE -coverpkg=$PACKAGES_COMMA -exec $DIR/test-xprog.sh $PACKAGES 2>&1 > >( tee output ) EXIT_STATUS=$? cat output | $GOBIN/go-junit-report > report.xml