From ce33ff7f17e43ba7314e91ca5a2d7db726cdf42b Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Mon, 5 Aug 2019 20:28:02 +0800 Subject: [PATCH 1/9] make testSuite --- Makefile | 6 +++++- executor/executor_test.go | 1 + store/mockstore/mocktikv/mock_tikv_test.go | 1 + store/tikv/backoff_test.go | 2 +- tools/check/check_testSuite.sh | 11 +++++++++++ 5 files changed, 19 insertions(+), 2 deletions(-) create mode 100755 tools/check/check_testSuite.sh diff --git a/Makefile b/Makefile index 2af63a547d3b9..0186a59b5cab3 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ build: # Install the check tools. check-setup:tools/bin/revive tools/bin/goword tools/bin/gometalinter tools/bin/gosec -check: fmt errcheck lint tidy check-static vet +check: fmt errcheck lint tidy testSuite check-static vet # These need to be fixed before they can be ran regularly check-fail: goword check-slow @@ -106,6 +106,10 @@ tidy: @echo "go mod tidy" ./tools/check/check-tidy.sh +testSuite: + @echo "testSuite" + ./tools/check/check_testSuite.sh + clean: $(GO) clean -i ./... rm -rf *.out diff --git a/executor/executor_test.go b/executor/executor_test.go index 459424924a301..cd874cd064342 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -90,6 +90,7 @@ var _ = Suite(&testSuite1{}) var _ = Suite(&testSuite2{}) var _ = Suite(&testSuite3{}) var _ = Suite(&testSuite4{}) +var _ = Suite(&testShowStatsSuite{testSuite{&baseTestSuite{}}}) var _ = Suite(&testBypassSuite{}) var _ = Suite(&testUpdateSuite{}) var _ = Suite(&testOOMSuite{}) diff --git a/store/mockstore/mocktikv/mock_tikv_test.go b/store/mockstore/mocktikv/mock_tikv_test.go index b5072107d812a..b76a5a11ed3d9 100644 --- a/store/mockstore/mocktikv/mock_tikv_test.go +++ b/store/mockstore/mocktikv/mock_tikv_test.go @@ -39,6 +39,7 @@ type testMVCCLevelDB struct { } var ( + _ = Suite(&testMockTiKVSuite{}) _ = Suite(&testMVCCLevelDB{}) _ = Suite(testMarshal{}) ) diff --git a/store/tikv/backoff_test.go b/store/tikv/backoff_test.go index 13aa5ef4c8fd2..d3e8c0ddf90fe 100644 --- a/store/tikv/backoff_test.go +++ b/store/tikv/backoff_test.go @@ -24,7 +24,7 @@ type testBackoffSuite struct { store *tikvStore } -var _ = Suite(&testLockSuite{}) +var _ = Suite(&testBackoffSuite{}) func (s *testBackoffSuite) SetUpTest(c *C) { s.store = NewTestStore(c).(*tikvStore) diff --git a/tools/check/check_testSuite.sh b/tools/check/check_testSuite.sh new file mode 100755 index 0000000000000..da4664daf959a --- /dev/null +++ b/tools/check/check_testSuite.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +exitCode=0 +for testSuite in `find -name "*_test.go" | xargs grep -P "type test(.*)Suite" | awk '{print $2}'`; do + # TODO: ugly regex + # TODO: check code comment + find -name "*_test.go" | xargs grep -P "_ = (check\.)?(Suite|SerialSuites)\((&?${testSuite}{|new\(${testSuite}\))" > /dev/null + [[ $? != 0 ]] && find -name "*_test.go" | xargs grep "func (s \*${testSuite}) Test" > /dev/null + [[ $? == 0 ]] && echo "${testSuite} is not enabled" && exitCode=1 +done +exit ${exitCode} From 81966005d04075f71e6dd8db25ed3cea29f0fb2b Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Mon, 5 Aug 2019 20:48:58 +0800 Subject: [PATCH 2/9] fix test --- store/tikv/backoff_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/tikv/backoff_test.go b/store/tikv/backoff_test.go index d3e8c0ddf90fe..ddf7d1fcf86f6 100644 --- a/store/tikv/backoff_test.go +++ b/store/tikv/backoff_test.go @@ -37,6 +37,6 @@ func (s *testBackoffSuite) TearDownTest(c *C) { func (s *testBackoffSuite) TestBackoffWithMax(c *C) { b := NewBackoffer(context.TODO(), 2000) err := b.BackoffWithMaxSleep(boTxnLockFast, 30, errors.New("test")) - c.Assert(err, NotNil) + c.Assert(err, IsNil) c.Assert(b.totalSleep, Equals, 30) } From 7f019c7966cf50941c2e16144f82c23d752cdbac Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Tue, 6 Aug 2019 11:38:31 +0800 Subject: [PATCH 3/9] make script compatible --- tools/check/check_testSuite.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/check/check_testSuite.sh b/tools/check/check_testSuite.sh index da4664daf959a..d7756ecd8980c 100755 --- a/tools/check/check_testSuite.sh +++ b/tools/check/check_testSuite.sh @@ -1,11 +1,15 @@ #!/bin/bash exitCode=0 -for testSuite in `find -name "*_test.go" | xargs grep -P "type test(.*)Suite" | awk '{print $2}'`; do +for testSuite in `find . -name "*_test.go" -print0 | xargs -0 grep -P "type test(.*)Suite" | awk '{print $2}'`; do # TODO: ugly regex # TODO: check code comment - find -name "*_test.go" | xargs grep -P "_ = (check\.)?(Suite|SerialSuites)\((&?${testSuite}{|new\(${testSuite}\))" > /dev/null - [[ $? != 0 ]] && find -name "*_test.go" | xargs grep "func (s \*${testSuite}) Test" > /dev/null - [[ $? == 0 ]] && echo "${testSuite} is not enabled" && exitCode=1 + if ! find . -name "*_test.go" -print0 | xargs -0 grep -P "_ = (check\.)?(Suite|SerialSuites)\((&?${testSuite}{|new\(${testSuite}\))" > /dev/null + then + if find . -name "*_test.go" -print0 | xargs -0 grep "func (s \*${testSuite}) Test" > /dev/null + then + echo "${testSuite} is not enabled" && exitCode=1 + fi + fi done exit ${exitCode} From 49bef6fc72c55aa53805335f6112878fde2b32fe Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Tue, 6 Aug 2019 11:40:39 +0800 Subject: [PATCH 4/9] make script compatible --- tools/check/check_testSuite.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/check/check_testSuite.sh b/tools/check/check_testSuite.sh index d7756ecd8980c..27086e8ae42cc 100755 --- a/tools/check/check_testSuite.sh +++ b/tools/check/check_testSuite.sh @@ -1,7 +1,7 @@ #!/bin/bash exitCode=0 -for testSuite in `find . -name "*_test.go" -print0 | xargs -0 grep -P "type test(.*)Suite" | awk '{print $2}'`; do +for testSuite in $(find . -name "*_test.go" -print0 | xargs -0 grep -P "type test(.*)Suite" | awk '{print $2}'); do # TODO: ugly regex # TODO: check code comment if ! find . -name "*_test.go" -print0 | xargs -0 grep -P "_ = (check\.)?(Suite|SerialSuites)\((&?${testSuite}{|new\(${testSuite}\))" > /dev/null From 0780c527b09d42b344f2968601a012aa21320589 Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Tue, 6 Aug 2019 12:02:27 +0800 Subject: [PATCH 5/9] make script compatible --- tools/check/check_testSuite.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/check/check_testSuite.sh b/tools/check/check_testSuite.sh index 27086e8ae42cc..cc8f9571b9fdd 100755 --- a/tools/check/check_testSuite.sh +++ b/tools/check/check_testSuite.sh @@ -2,11 +2,11 @@ exitCode=0 for testSuite in $(find . -name "*_test.go" -print0 | xargs -0 grep -P "type test(.*)Suite" | awk '{print $2}'); do - # TODO: ugly regex - # TODO: check code comment - if ! find . -name "*_test.go" -print0 | xargs -0 grep -P "_ = (check\.)?(Suite|SerialSuites)\((&?${testSuite}{|new\(${testSuite}\))" > /dev/null - then - if find . -name "*_test.go" -print0 | xargs -0 grep "func (s \*${testSuite}) Test" > /dev/null + # TODO: ugly regex + # TODO: check code comment + if ! find . -name "*_test.go" -print0 | xargs -0 grep -P "_ = (check\.)?(Suite|SerialSuites)\((&?${testSuite}{|new\(${testSuite}\))" > /dev/null + then + if find . -name "*_test.go" -print0 | xargs -0 grep "func (s \*${testSuite}) Test" > /dev/null then echo "${testSuite} is not enabled" && exitCode=1 fi From fbaf3d95dc343801a619eda770bd55c1cd4b0138 Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Tue, 6 Aug 2019 13:17:05 +0800 Subject: [PATCH 6/9] make script compatible --- tools/check/check_testSuite.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/check/check_testSuite.sh b/tools/check/check_testSuite.sh index cc8f9571b9fdd..41d0fb310186b 100755 --- a/tools/check/check_testSuite.sh +++ b/tools/check/check_testSuite.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -euo pipefail + exitCode=0 for testSuite in $(find . -name "*_test.go" -print0 | xargs -0 grep -P "type test(.*)Suite" | awk '{print $2}'); do # TODO: ugly regex From c7dd491959ca1464d189858afc4856782f7a4880 Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Tue, 6 Aug 2019 19:18:01 +0800 Subject: [PATCH 7/9] make script compatible --- tools/check/check_testSuite.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/check/check_testSuite.sh b/tools/check/check_testSuite.sh index 41d0fb310186b..dd743df3830bf 100755 --- a/tools/check/check_testSuite.sh +++ b/tools/check/check_testSuite.sh @@ -8,7 +8,7 @@ for testSuite in $(find . -name "*_test.go" -print0 | xargs -0 grep -P "type tes # TODO: check code comment if ! find . -name "*_test.go" -print0 | xargs -0 grep -P "_ = (check\.)?(Suite|SerialSuites)\((&?${testSuite}{|new\(${testSuite}\))" > /dev/null then - if find . -name "*_test.go" -print0 | xargs -0 grep "func (s \*${testSuite}) Test" > /dev/null + if find . -name "*_test.go" -print0 | xargs -0 grep -P "func \((.* )?\*?${testSuite}\) Test" > /dev/null then echo "${testSuite} is not enabled" && exitCode=1 fi From c5aeb8a6f0f0e769a07fdf53ca7e0343e7ec68dc Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Thu, 8 Aug 2019 15:11:26 +0800 Subject: [PATCH 8/9] address comment --- executor/executor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/executor_test.go b/executor/executor_test.go index cd874cd064342..c3278b92804bc 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -90,7 +90,7 @@ var _ = Suite(&testSuite1{}) var _ = Suite(&testSuite2{}) var _ = Suite(&testSuite3{}) var _ = Suite(&testSuite4{}) -var _ = Suite(&testShowStatsSuite{testSuite{&baseTestSuite{}}}) +var _ = SerialSuites(&testShowStatsSuite{testSuite{&baseTestSuite{}}}) var _ = Suite(&testBypassSuite{}) var _ = Suite(&testUpdateSuite{}) var _ = Suite(&testOOMSuite{}) From 3d439bf2a67b8cc17aebde1cf5adb9012710585d Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Sat, 10 Aug 2019 16:22:23 +0800 Subject: [PATCH 9/9] fix --- executor/executor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/executor_test.go b/executor/executor_test.go index 75ad0dbd4893b..8de5009b0b900 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -90,7 +90,7 @@ var _ = Suite(&testSuite1{}) var _ = Suite(&testSuite2{}) var _ = Suite(&testSuite3{}) var _ = Suite(&testSuite4{}) -var _ = SerialSuites(&testShowStatsSuite{testSuite{&baseTestSuite{}}}) +var _ = SerialSuites(&testShowStatsSuite{testSuite{}}) var _ = Suite(&testBypassSuite{}) var _ = Suite(&testUpdateSuite{}) var _ = Suite(&testOOMSuite{})