From 10bafb3efb5e7fd920307569e58d11b283063cbb Mon Sep 17 00:00:00 2001 From: Xuecheng Zhang Date: Wed, 11 Dec 2019 11:40:36 +0800 Subject: [PATCH] *: split unit test according to upstream MySQL (#416) --- Makefile | 27 ++++++++++++++++++++++++--- dm/worker/worker_test.go | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 8638d6f515..34c71af931 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,10 @@ GO := GO111MODULE=on go GOBUILD := CGO_ENABLED=0 $(GO) build GOTEST := CGO_ENABLED=1 $(GO) test PACKAGES := $$(go list ./... | grep -vE 'tests|cmd|vendor|pbmock') +PACKAGES_RELAY := $$(go list ./... | grep 'github.com/pingcap/dm/relay') +PACKAGES_SYNCER := $$(go list ./... | grep 'github.com/pingcap/dm/syncer') +PACKAGES_PKG_BINLOG := $$(go list ./... | grep 'github.com/pingcap/dm/pkg/binlog') +PACKAGES_OTHERS := $$(go list ./... | grep -vE 'tests|cmd|vendor|pbmock|github.com/pingcap/dm/relay|github.com/pingcap/dm/syncer|github.com/pingcap/dm/pkg/binlog') FILES := $$(find . -name "*.go" | grep -vE "vendor") TOPDIRS := $$(ls -d */ | grep -vE "vendor") SHELL := /usr/bin/env bash @@ -67,15 +71,32 @@ debug-tools: test: unit_test integration_test -unit_test: +define run_unit_test + @echo "running unit test for packages:" $(1) bash -x ./tests/wait_for_mysql.sh mkdir -p $(TEST_DIR) which $(FAILPOINT) >/dev/null 2>&1 || $(GOBUILD) -o $(FAILPOINT) github.com/pingcap/failpoint/failpoint-ctl $(FAILPOINT_ENABLE) @export log_level=error; \ - $(GOTEST) -covermode=atomic -coverprofile="$(TEST_DIR)/cov.unit_test.out" $(TEST_RACE_FLAG) $(PACKAGES) \ + $(GOTEST) -covermode=atomic -coverprofile="$(TEST_DIR)/cov.$(2).out" $(TEST_RACE_FLAG) $(1) \ || { $(FAILPOINT_DISABLE); exit 1; } $(FAILPOINT_DISABLE) +endef + +unit_test: + $(call run_unit_test,$(PACKAGES),unit_test) + +unit_test_relay: + $(call run_unit_test,$(PACKAGES_RELAY),unit_test_relay) + +unit_test_syncer: + $(call run_unit_test,$(PACKAGES_SYNCER),unit_test_syncer) + +unit_test_pkg_binlog: + $(call run_unit_test,$(PACKAGES_PKG_BINLOG),unit_test_pkg_binlog) + +unit_test_others: + $(call run_unit_test,$(PACKAGES_OTHERS),unit_test_others) check: fmt lint vet terror_check @@ -151,7 +172,7 @@ coverage_fix_cover_mode: coverage: coverage_fix_cover_mode GO111MODULE=off go get github.com/zhouqiang-cl/gocovmerge gocovmerge "$(TEST_DIR)"/cov.* | grep -vE ".*.pb.go|.*.__failpoint_binding__.go" > "$(TEST_DIR)/all_cov.out" - grep -vE ".*.pb.go|.*.__failpoint_binding__.go" $(TEST_DIR)/cov.unit_test.out > $(TEST_DIR)/unit_test.out + gocovmerge "$(TEST_DIR)"/cov.unit_test*.out | grep -vE ".*.pb.go|.*.__failpoint_binding__.go" > $(TEST_DIR)/unit_test.out ifeq ("$(JenkinsCI)", "1") GO111MODULE=off go get github.com/mattn/goveralls @goveralls -coverprofile=$(TEST_DIR)/all_cov.out -service=jenkins-ci -repotoken $(COVERALLS_TOKEN) diff --git a/dm/worker/worker_test.go b/dm/worker/worker_test.go index 6de376694f..30dec19cb4 100644 --- a/dm/worker/worker_test.go +++ b/dm/worker/worker_test.go @@ -167,7 +167,7 @@ func (t *testServer) TestTaskAutoResume(c *C) { c.Assert(err, IsNil) // check task in paused state - c.Assert(utils.WaitSomething(10, 100*time.Millisecond, func() bool { + c.Assert(utils.WaitSomething(100, 100*time.Millisecond, func() bool { for _, st := range s.worker.QueryStatus(taskName) { if st.Name == taskName && st.Stage == pb.Stage_Paused { return true