Skip to content

Commit

Permalink
ut, makefile: consolidate unit tests into single makefile target (#910)
Browse files Browse the repository at this point in the history
close #909
  • Loading branch information
wlwilliamx authored Jan 17, 2025
1 parent 7b49a26 commit 712d90a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ tools/workload/bin
.idea
*.log
.DS_Store

# Unit test reports
cdc-junit-report.xml
35 changes: 34 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Phony targets are targets that are not associated with files.
# Add new phony targets here to make them available in the `make` command.
.PHONY: clean fmt check tidy \
generate-protobuf generate_mock \
cdc kafka_consumer storage_consumer pulsar_consumer filter_helper \
unit_test_in_verify_ci integration_test_build integration_test_mysql integration_test_kafka integration_test_storage integration_test_pulsar \


FAIL_ON_STDOUT := awk '{ print } END { if (NR > 0) { exit 1 } }'

PROJECT=ticdc
Expand Down Expand Up @@ -36,7 +44,7 @@ GOVERSION := $(shell go version)
# ref: https://github.com/pingcap/tidb/pull/39526#issuecomment-1407952955
OS := "$(shell go env GOOS)"
SED_IN_PLACE ?= $(shell which sed)
IS_ALPINE := $(shell grep -qi Alpine /etc/os-release && echo 1)
IS_ALPINE := $(shell if [ -f /etc/os-release ]; then grep -qi Alpine /etc/os-release && echo 1; else echo 0; fi)
ifeq (${OS}, "linux")
CGO := 0
SED_IN_PLACE += -i
Expand Down Expand Up @@ -99,6 +107,16 @@ FAILPOINT := tools/bin/failpoint-ctl
FAILPOINT_ENABLE := $$(echo $(FAILPOINT_DIR) | xargs $(FAILPOINT) enable >/dev/null)
FAILPOINT_DISABLE := $$(echo $(FAILPOINT_DIR) | xargs $(FAILPOINT) disable >/dev/null)

# go test -p parameter for unit tests
P=3

# The following packages are used in unit tests.
# Add new packages here if you want to include them in unit tests.
UT_PACKAGES_DISPATCHER := ./pkg/sink/mysql/... ./pkg/sink/util/... ./downstreamadapter/sink/... ./downstreamadapter/dispatcher/... ./downstreamadapter/worker/... ./pkg/sink/codec/open/... ./pkg/sink/codec/canal/...
UT_PACKAGES_MAINTAINER := ./maintainer/...
UT_PACKAGES_COORDINATOR := ./coordinator/...
UT_PACKAGES_OTHERS := ./pkg/eventservice/... ./utils/dynstream/...

include tools/Makefile

generate-protobuf:
Expand Down Expand Up @@ -188,6 +206,21 @@ unit_test: check_failpoint_ctl generate-protobuf
|| { $(FAILPOINT_DISABLE); exit 1; }
$(FAILPOINT_DISABLE)

unit_test_in_verify_ci: check_failpoint_ctl tools/bin/gotestsum tools/bin/gocov tools/bin/gocov-xml
mkdir -p "$(TEST_DIR)"
$(FAILPOINT_ENABLE)
@echo "Running unit tests..."
@export log_level=error;\
CGO_ENABLED=1 tools/bin/gotestsum --junitfile cdc-junit-report.xml -- -v -timeout 120s -p $(P) --race --tags=intest \
-covermode=atomic -coverprofile="$(TEST_DIR)/cov.unit.out" \
$(UT_PACKAGES_DISPATCHER) \
$(UT_PACKAGES_MAINTAINER) \
$(UT_PACKAGES_COORDINATOR) \
$(UT_PACKAGES_OTHERS) \
|| { $(FAILPOINT_DISABLE); exit 1; }
tools/bin/gocov convert "$(TEST_DIR)/cov.unit.out" | tools/bin/gocov-xml > cdc-coverage.xml
$(FAILPOINT_DISABLE)

tidy:
@echo "go mod tidy"
./tools/check/check-tidy.sh
Expand Down

0 comments on commit 712d90a

Please sign in to comment.