@@ -93,7 +93,7 @@ multiplatform ?= false
9393env ?= env GOOS=$(os ) GOARCH=$(arch )
9494build_flags ?= -buildvcs=false
9595release_build_flags ?= $(build_flags ) -ldflags '-w -s'
96- test_cmd ?= scripts/test-packages.sh
96+ test_flags ?=
9797proto_flags ?=
9898
9999ifneq ("$(wildcard /usr/include) ","")
@@ -136,48 +136,60 @@ COR_DB_PACKAGES=$(shell $(go_cmd) list ./... | grep -E "$(CORE_DB_PACKAGES_REGEX
136136REQUIRES_DB_PACKAGES =$(shell $(go_cmd ) list ./... | grep -E "$(REQUIRES_DB_PACKAGES_REGEXP ) ")
137137NO_DB_PACKAGES =$(shell $(go_cmd ) list ./... | grep -vE "$(CORE_DB_PACKAGES_REGEXP ) |$(REQUIRES_DB_PACKAGES_REGEXP ) |$(HEAVY_PACKAGES_REGEXP ) ")
138138
139+ # Uses "gotestsum" to summerize the output.
140+ # * "--rerun-fails=0" is used to re-run failed test (once).
141+ # The re-run serves two purposes.
142+ # 1. Conveniently show the failed test at the end along with their output, to allow easy debugging.
143+ # 2. Mitigate flaky tests.
144+ # * "--format dots" is used to print a "." for passed test, and "x" for a failed test.
145+ # This reduces the output clutter.
146+ # Failed tests output will be showed at the end when they re-run.
147+ # Successful tests' output is not shown.
148+ # * "--packages ${packages}" is required to support "--rerun-fails=0".
149+ test_method = gotestsum --rerun-fails=0 --format dots --packages "$(1 ) " -- -v -timeout 30m $(test_flags ) $(2 )
150+ test_method_with_coverage = $(call test_method, $(1 ) , $(2 ) -coverprofile=coverage.profile -coverpkg=./...)
151+
139152# Excludes integration and container tests.
140153# Use `test-integration`, `test-integration-db-resiliency`, and `test-container`.
141154test : build
142- @$(test_cmd ) " ${NON_HEAVY_PACKAGES} "
155+ @$(call test_method, ${NON_HEAVY_PACKAGES})
143156
144157# Test a specific package.
145158test-package-% : build
146- @$(test_cmd ) ./$* /...
159+ @$(call test_method, ./$* /...)
147160
148161# Integration tests excluding DB resiliency tests.
149162# Use `test-integration-db-resiliency`.
150163test-integration : build
151- @$(test_cmd ) ./integration/... -skip " DBResiliency.*"
164+ @$(call test_method, ./integration/..., -skip "DBResiliency.* ")
152165
153166# DB resiliency integration tests.
154167test-integration-db-resiliency : build
155- @$(test_cmd ) ./integration/... -run " DBResiliency.*"
168+ @$(call test_method, ./integration/..., -run "DBResiliency.* ")
156169
157170# Tests the all-in-one docker image.
158171test-container : build-image-test-node build-image-release
159- @$(test_cmd ) ./docker/...
172+ @$(call test_method, ./docker/...)
160173
161174# Tests for components that directly talk to the DB, where different DBs might affect behaviour.
162175test-core-db : FORCE
163- @$(test_cmd ) " ${COR_DB_PACKAGES} "
176+ @$(call test_method, ${COR_DB_PACKAGES})
164177
165178# Tests for components that depend on the DB layer, but are agnostic to the specific DB used.
166179test-requires-db : FORCE
167- @$(test_cmd ) " ${REQUIRES_DB_PACKAGES} "
180+ @$(call test_method, ${REQUIRES_DB_PACKAGES})
168181
169182# Tests that require no DB at all, e.g., pure logic, utilities
170183test-no-db : FORCE
171- @$(test_cmd ) " ${NO_DB_PACKAGES} " -coverprofile=coverage.profile -coverpkg=./...
184+ @$(call test_method_with_coverage, ${NO_DB_PACKAGES})
172185
173186# Tests for components that depend on the DB layer, and ones that are agnostic to the specific DB used.
174187test-all-db : FORCE
175- @$(test_cmd ) " ${REQUIRES_DB_PACKAGES} ${COR_DB_PACKAGES} " -coverprofile=coverage.profile -coverpkg=./...
188+ @$(call test_method_with_coverage, ${REQUIRES_DB_PACKAGES} ${COR_DB_PACKAGES})
176189
177190# Runs test coverage analysis. It uses same tests that will be covered by the CI.
178191test-cover : FORCE
179- @$(test_cmd ) " ${NO_DB_PACKAGES} ${REQUIRES_DB_PACKAGES} ${COR_DB_PACKAGES} " \
180- -coverprofile=coverage.profile -coverpkg=./...
192+ @$(call test_method_with_coverage, ${NO_DB_PACKAGES} ${REQUIRES_DB_PACKAGES} ${COR_DB_PACKAGES})
181193 @scripts/test-coverage-filter-files.sh
182194
183195cover-report : FORCE
0 commit comments