Skip to content

Commit ac8717c

Browse files
authored
Separate integration tests and unit tests (#3760)
* Separate integration tests and unit tests
1 parent a026002 commit ac8717c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1746
-2844
lines changed

Makefile

+29-17
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ endef
5959

6060
TEST_TIMEOUT := 20m
6161

62+
# TODO: INTEG_TEST should be functional tests
6263
INTEG_TEST_ROOT := ./host
6364
INTEG_TEST_XDC_ROOT := ./host/xdc
6465
INTEG_TEST_NDC_ROOT := ./host/ndc
6566

67+
PERSISTENCE_INTEGRATION_TEST_ROOT := ./common/persistence/tests
68+
DB_TOOL_INTEGRATION_TEST_ROOT := ./tools/tests
69+
6670
PROTO_ROOT := proto
6771
PROTO_FILES = $(shell find ./$(PROTO_ROOT)/internal -name "*.proto")
6872
PROTO_DIRS = $(sort $(dir $(PROTO_FILES)))
@@ -75,7 +79,7 @@ ALL_SCRIPTS := $(shell find . -name "*.sh")
7579
# TODO (jeremy): Replace below with build tags and `go test ./...` for targets
7680
TEST_DIRS := $(sort $(dir $(filter %_test.go,$(ALL_SRC))))
7781
INTEG_TEST_DIRS := $(filter $(INTEG_TEST_ROOT)/ $(INTEG_TEST_NDC_ROOT)/,$(TEST_DIRS))
78-
UNIT_TEST_DIRS := $(filter-out $(INTEG_TEST_ROOT)% $(INTEG_TEST_XDC_ROOT)% $(INTEG_TEST_NDC_ROOT)%,$(TEST_DIRS))
82+
UNIT_TEST_DIRS := $(filter-out $(INTEG_TEST_ROOT)% $(INTEG_TEST_XDC_ROOT)% $(INTEG_TEST_NDC_ROOT)% $(PERSISTENCE_INTEGRATION_TEST_ROOT)% $(DB_TOOL_INTEGRATION_TEST_ROOT)%,$(TEST_DIRS))
7983

8084
# go.opentelemetry.io/otel/sdk/metric@v0.31.0 - there are breaking changes in v0.32.0.
8185
# github.com/urfave/cli/v2@v2.4.0 - needs to accept comma in values before unlocking https://github.com/urfave/cli/pull/1241.
@@ -87,6 +91,8 @@ PINNED_DEPENDENCIES := \
8791
# Code coverage output files.
8892
COVER_ROOT := ./.coverage
8993
UNIT_COVER_PROFILE := $(COVER_ROOT)/unit_coverprofile.out
94+
INTEGRATION_COVER_PROFILE := $(COVER_ROOT)/integration_coverprofile.out
95+
DB_TOOL_COVER_PROFILE := $(COVER_ROOT)/db_tool_coverprofile.out
9096
INTEG_COVER_PROFILE := $(COVER_ROOT)/integ_$(PERSISTENCE_DRIVER)_coverprofile.out
9197
INTEG_XDC_COVER_PROFILE := $(COVER_ROOT)/integ_xdc_$(PERSISTENCE_DRIVER)_coverprofile.out
9298
INTEG_NDC_COVER_PROFILE := $(COVER_ROOT)/integ_ndc_$(PERSISTENCE_DRIVER)_coverprofile.out
@@ -254,32 +260,34 @@ build-tests:
254260
@printf $(COLOR) "Build tests..."
255261
@go test -exec="true" -count=0 -tags=esintegration $(TEST_DIRS)
256262

257-
unit-test:
263+
unit-test: clean-test-results
258264
@printf $(COLOR) "Run unit tests..."
259-
$(foreach UNIT_TEST_DIR,$(UNIT_TEST_DIRS),\
260-
@go test $(UNIT_TEST_DIR) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -race | tee -a test.log \
261-
$(NEWLINE))
265+
@go test $(UNIT_TEST_DIRS) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -race | tee -a test.log
266+
@! grep -q "^--- FAIL" test.log
267+
268+
db-integration-test: clean-test-results
269+
@printf $(COLOR) "Run integration tests..."
270+
@go test $(PERSISTENCE_INTEGRATION_TEST_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) | tee -a test.log
271+
@go test $(DB_TOOL_INTEGRATION_TEST_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) | tee -a test.log
262272
@! grep -q "^--- FAIL" test.log
263273

274+
# TODO: rename it to functional-test
264275
integration-test: clean-test-results
265276
@printf $(COLOR) "Run integration tests..."
266-
$(foreach INTEG_TEST_DIR,$(INTEG_TEST_DIRS),\
267-
@go test $(INTEG_TEST_DIR) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -race | tee -a test.log \
268-
$(NEWLINE))
277+
@go test $(INTEG_TEST_DIRS) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -race | tee -a test.log
269278
# Need to run xdc tests with race detector off because of ringpop bug causing data race issue.
270279
@go test $(INTEG_TEST_XDC_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) | tee -a test.log
271280
@! grep -q "^--- FAIL" test.log
272281

282+
# TODO: rename it to functional-test
273283
integration-with-fault-injection-test: clean-test-results
274284
@printf $(COLOR) "Run integration tests with fault injection..."
275-
$(foreach INTEG_TEST_DIR,$(INTEG_TEST_DIRS),\
276-
@go test $(INTEG_TEST_DIR) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -race -PersistenceFaultInjectionRate=0.005 | tee -a test.log \
277-
$(NEWLINE))
285+
@go test $(INTEG_TEST_DIRS) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -race -PersistenceFaultInjectionRate=0.005 | tee -a test.log
278286
# Need to run xdc tests with race detector off because of ringpop bug causing data race issue.
279287
@go test $(INTEG_TEST_XDC_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -PersistenceFaultInjectionRate=0.005 | tee -a test.log
280288
@! grep -q "^--- FAIL" test.log
281289

282-
test: unit-test integration-test integration-with-fault-injection-test
290+
test: unit-test db-integration-test integration-test integration-with-fault-injection-test
283291

284292
##### Coverage #####
285293
$(COVER_ROOT):
@@ -288,20 +296,24 @@ $(COVER_ROOT):
288296
unit-test-coverage: $(COVER_ROOT)
289297
@printf $(COLOR) "Run unit tests with coverage..."
290298
@echo "mode: atomic" > $(UNIT_COVER_PROFILE)
291-
$(foreach UNIT_TEST_DIR,$(patsubst ./%/,%,$(UNIT_TEST_DIRS)),\
292-
@mkdir -p $(COVER_ROOT)/$(UNIT_TEST_DIR); \
293-
go test ./$(UNIT_TEST_DIR) -timeout=$(TEST_TIMEOUT) -race -coverprofile=$(COVER_ROOT)/$(UNIT_TEST_DIR)/coverprofile.out || exit 1; \
294-
grep -v -e "^mode: \w\+" $(COVER_ROOT)/$(UNIT_TEST_DIR)/coverprofile.out >> $(UNIT_COVER_PROFILE) || true \
295-
$(NEWLINE))
299+
@go test ./$(UNIT_TEST_DIRS) -timeout=$(TEST_TIMEOUT) -race -coverprofile=$(UNIT_COVER_PROFILE) || exit 1;
300+
301+
db-integration-test-coverage: $(COVER_ROOT)
302+
@printf $(COLOR) "Run integration tests with coverage..."
303+
@go test $(PERSISTENCE_INTEGRATION_TEST_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -coverpkg="./common/..." -coverprofile=$(INTEGRATION_COVER_PROFILE)
304+
@go test $(DB_TOOL_INTEGRATION_TEST_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -coverpkg="./tools/..." -coverprofile=$(DB_TOOL_COVER_PROFILE)
296305

306+
# TODO: rename it to functional-test
297307
integration-test-coverage: $(COVER_ROOT)
298308
@printf $(COLOR) "Run integration tests with coverage with $(PERSISTENCE_DRIVER) driver..."
299309
@go test $(INTEG_TEST_ROOT) -timeout=$(TEST_TIMEOUT) -race $(TEST_TAG) -persistenceType=$(PERSISTENCE_TYPE) -persistenceDriver=$(PERSISTENCE_DRIVER) $(INTEG_TEST_COVERPKG) -coverprofile=$(INTEG_COVER_PROFILE)
300310

311+
# TODO: rename it to functional-test
301312
integration-test-xdc-coverage: $(COVER_ROOT)
302313
@printf $(COLOR) "Run integration test for cross DC with coverage with $(PERSISTENCE_DRIVER) driver..."
303314
@go test $(INTEG_TEST_XDC_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -persistenceType=$(PERSISTENCE_TYPE) -persistenceDriver=$(PERSISTENCE_DRIVER) $(INTEG_TEST_COVERPKG) -coverprofile=$(INTEG_XDC_COVER_PROFILE)
304315

316+
# TODO: rename it to functional-test
305317
integration-test-ndc-coverage: $(COVER_ROOT)
306318
@printf $(COLOR) "Run integration test for NDC with coverage with $(PERSISTENCE_DRIVER) driver..."
307319
@go test $(INTEG_TEST_NDC_ROOT) -timeout=$(TEST_TIMEOUT) -race $(TEST_TAG) -persistenceType=$(PERSISTENCE_TYPE) -persistenceDriver=$(PERSISTENCE_DRIVER) $(INTEG_TEST_COVERPKG) -coverprofile=$(INTEG_NDC_COVER_PROFILE)

common/persistence/persistence-tests/cassandra_test.go

-59
This file was deleted.

common/persistence/persistence-tests/mysql_test.go

-59
This file was deleted.

common/persistence/persistence-tests/postgres_test.go

-70
This file was deleted.

common/persistence/persistence-tests/sqlite_test.go

-87
This file was deleted.

common/persistence/sql/sqlplugin/tests/history_current_execution_test.go common/persistence/sql/sqlplugin/tests/history_current_execution.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var (
6969
}
7070
)
7171

72-
func newHistoryCurrentExecutionSuite(
72+
func NewHistoryCurrentExecutionSuite(
7373
t *testing.T,
7474
store sqlplugin.HistoryExecution,
7575
) *historyCurrentExecutionSuite {

0 commit comments

Comments
 (0)