Skip to content

Commit

Permalink
executor: speed up test (pingcap#12896)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunRunAway authored and XiaTianliang committed Dec 21, 2019
1 parent 103f135 commit e1b43fa
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 64 deletions.
2 changes: 1 addition & 1 deletion executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func (s *testSuite5) TestAdminCheckTableFailed(c *C) {
tk.MustExec("admin check table admin_test")
}

func (s *testSuite1) TestAdminCheckTable(c *C) {
func (s *testSuite2) TestAdminCheckTable(c *C) {
// test NULL value.
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
38 changes: 21 additions & 17 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import (
"github.com/pingcap/tidb/util/testkit"
)

func (s *testSuite1) TestAggregation(c *C) {
type testSuiteAgg struct {
*baseTestSuite
}

func (s *testSuiteAgg) TestAggregation(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set @@tidb_hash_join_concurrency=1")
tk.MustExec("use test")
Expand Down Expand Up @@ -353,7 +357,7 @@ func (s *testSuite1) TestAggregation(c *C) {
c.Assert(errors.Cause(err).Error(), Equals, "unsupported agg function: var_samp")
}

func (s *testSuite1) TestAggPrune(c *C) {
func (s *testSuiteAgg) TestAggPrune(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
Expand All @@ -377,7 +381,7 @@ func (s *testSuite1) TestAggPrune(c *C) {
tk.MustQuery("SELECT a, MIN(b), MAX(b) FROM t GROUP BY a").Check(testkit.Rows("1 11 11", "3 <nil> <nil>"))
}

func (s *testSuite1) TestGroupConcatAggr(c *C) {
func (s *testSuiteAgg) TestGroupConcatAggr(c *C) {
// issue #5411
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down Expand Up @@ -410,7 +414,7 @@ func (s *testSuite1) TestGroupConcatAggr(c *C) {
tk.MustQuery("select group_concat(123, null)").Check(testkit.Rows("<nil>"))
}

func (s *testSuite) TestSelectDistinct(c *C) {
func (s *testSuiteAgg) TestSelectDistinct(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
s.fillData(tk, "select_distinct_test")
Expand All @@ -422,7 +426,7 @@ func (s *testSuite) TestSelectDistinct(c *C) {

}

func (s *testSuite1) TestAggPushDown(c *C) {
func (s *testSuiteAgg) TestAggPushDown(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
Expand Down Expand Up @@ -450,7 +454,7 @@ func (s *testSuite1) TestAggPushDown(c *C) {
tk.MustQuery("select a, count(b) from (select * from t union all select * from tt) k group by a order by a").Check(testkit.Rows("1 2", "2 1"))
}

func (s *testSuite1) TestOnlyFullGroupBy(c *C) {
func (s *testSuiteAgg) TestOnlyFullGroupBy(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set sql_mode = 'ONLY_FULL_GROUP_BY'")
Expand Down Expand Up @@ -562,7 +566,7 @@ func (s *testSuite1) TestOnlyFullGroupBy(c *C) {
c.Assert(terror.ErrorEqual(err, plannercore.ErrAmbiguous), IsTrue, Commentf("err %v", err))
}

func (s *testSuite1) TestHaving(c *C) {
func (s *testSuiteAgg) TestHaving(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)

tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'")
Expand All @@ -587,7 +591,7 @@ func (s *testSuite1) TestHaving(c *C) {
tk.MustQuery("select 1 from t group by c1 having sum(abs(c2 + c3)) = c1").Check(testkit.Rows("1"))
}

func (s *testSuite1) TestAggEliminator(c *C) {
func (s *testSuiteAgg) TestAggEliminator(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)

tk.MustExec("create table t(a int primary key, b int)")
Expand All @@ -600,7 +604,7 @@ func (s *testSuite1) TestAggEliminator(c *C) {
tk.MustQuery("select group_concat(b, b) from t group by a").Sort().Check(testkit.Rows("-1-1", "-2-2", "11", "<nil>"))
}

func (s *testSuite1) TestMaxMinFloatScalaFunc(c *C) {
func (s *testSuiteAgg) TestMaxMinFloatScalaFunc(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)

tk.MustExec(`DROP TABLE IF EXISTS T;`)
Expand All @@ -610,7 +614,7 @@ func (s *testSuite1) TestMaxMinFloatScalaFunc(c *C) {
tk.MustQuery(`SELECT MIN(CASE B WHEN 'val_b' THEN C ELSE 0 END) val_b FROM T WHERE cast(A as signed) = 0 GROUP BY a;`).Check(testkit.Rows("12.190999984741211"))
}

func (s *testSuite1) TestBuildProjBelowAgg(c *C) {
func (s *testSuiteAgg) TestBuildProjBelowAgg(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (i int);")
Expand All @@ -622,7 +626,7 @@ func (s *testSuite1) TestBuildProjBelowAgg(c *C) {
"4 3 18 7,7,7 8"))
}

func (s *testSuite1) TestInjectProjBelowTopN(c *C) {
func (s *testSuiteAgg) TestInjectProjBelowTopN(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (i int);")
Expand All @@ -648,7 +652,7 @@ func (s *testSuite1) TestInjectProjBelowTopN(c *C) {
tk.MustQuery("select i, i, i from t order by i + 1").Check(testkit.Rows("1 1 1", "1 1 1", "1 1 1", "2 2 2", "2 2 2", "2 2 2", "3 3 3", "3 3 3", "3 3 3"))
}

func (s *testSuite1) TestFirstRowEnum(c *C) {
func (s *testSuiteAgg) TestFirstRowEnum(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec(`use test;`)
tk.MustExec(`drop table if exists t;`)
Expand All @@ -659,7 +663,7 @@ func (s *testSuite1) TestFirstRowEnum(c *C) {
))
}

func (s *testSuite1) TestAggJSON(c *C) {
func (s *testSuiteAgg) TestAggJSON(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec(`drop table if exists t;`)
tk.MustExec(`create table t(a datetime, b json, index idx(a));`)
Expand Down Expand Up @@ -708,23 +712,23 @@ func (s *testSuite1) TestAggJSON(c *C) {
))
}

func (s *testSuite1) TestIssue10099(c *C) {
func (s *testSuiteAgg) TestIssue10099(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a char(10), b char(10))")
tk.MustExec("insert into t values('1', '222'), ('12', '22')")
tk.MustQuery("select count(distinct a, b) from t").Check(testkit.Rows("2"))
}

func (s *testSuite1) TestIssue10098(c *C) {
func (s *testSuiteAgg) TestIssue10098(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec(`drop table if exists t;`)
tk.MustExec("create table t(a char(10), b char(10))")
tk.MustExec("insert into t values('1', '222'), ('12', '22')")
tk.MustQuery("select group_concat(distinct a, b) from t").Check(testkit.Rows("1222,1222"))
}

func (s *testSuite1) TestIssue10608(c *C) {
func (s *testSuiteAgg) TestIssue10608(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec(`drop table if exists t, s;`)
tk.MustExec("create table t(a int)")
Expand All @@ -736,7 +740,7 @@ func (s *testSuite1) TestIssue10608(c *C) {

}

func (s *testSuite1) TestIssue12759HashAggCalledByApply(c *C) {
func (s *testSuiteAgg) TestIssue12759HashAggCalledByApply(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.Se.GetSessionVars().HashAggFinalConcurrency = 4
tk.MustExec(`insert into mysql.opt_rule_blacklist value("decorrelate");`)
Expand Down
2 changes: 1 addition & 1 deletion executor/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (s *testSuite1) TestAnalyzeFastSample(c *C) {
c.Assert(fmt.Sprintln(vals), Equals, "[[0 4 6 9 10 11 12 14 17 24 25 29 30 34 35 44 52 54 57 58] [0 4 6 9 10 11 12 14 17 24 25 29 30 34 35 44 52 54 57 58]]\n")
}

func (s *testSuite1) TestFastAnalyze(c *C) {
func (s *testFastAnalyze) TestFastAnalyze(c *C) {
cluster := mocktikv.NewCluster()
mocktikv.BootstrapWithSingleStore(cluster)
store, err := mockstore.NewMockTikvStore(
Expand Down
2 changes: 1 addition & 1 deletion executor/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func (s *testSuite6) TestTooLargeIdentifierLength(c *C) {
c.Assert(err.Error(), Equals, fmt.Sprintf("[ddl:1059]Identifier name '%s' is too long", indexName2))
}

func (s *testSuite6) TestShardRowIDBits(c *C) {
func (s *testSuite8) TestShardRowIDBits(c *C) {
tk := testkit.NewTestKit(c, s.store)

tk.MustExec("use test")
Expand Down
40 changes: 35 additions & 5 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ func TestT(t *testing.T) {
logLevel := os.Getenv("log_level")
logutil.InitLogger(logutil.NewLogConfig(logLevel, logutil.DefaultLogFormat, "", logutil.EmptyFileLogConfig, false))
autoid.SetStep(5000)

old := config.GetGlobalConfig()
new := *old
new.Log.SlowThreshold = 30000 // 30s
config.StoreGlobalConfig(&new)

testleak.BeforeTest()
TestingT(t)
testleak.AfterTestT(t)()
Expand All @@ -96,8 +102,13 @@ var _ = Suite(&testSuite2{&baseTestSuite{}})
var _ = Suite(&testSuite3{&baseTestSuite{}})
var _ = Suite(&testSuite4{&baseTestSuite{}})
var _ = Suite(&testSuite5{&baseTestSuite{}})
var _ = Suite(&testSuiteJoin1{&baseTestSuite{}})
var _ = Suite(&testSuiteJoin2{&baseTestSuite{}})
var _ = Suite(&testSuiteJoin3{&baseTestSuite{}})
var _ = Suite(&testSuiteAgg{&baseTestSuite{}})
var _ = Suite(&testSuite6{&baseTestSuite{}})
var _ = Suite(&testSuite7{&baseTestSuite{}})
var _ = Suite(&testSuite8{&baseTestSuite{}})
var _ = SerialSuites(&testShowStatsSuite{&baseTestSuite{}})
var _ = Suite(&testBypassSuite{})
var _ = Suite(&testUpdateSuite{})
Expand Down Expand Up @@ -1407,7 +1418,7 @@ func (s *testSuiteP1) TestTablePKisHandleScan(c *C) {
}
}

func (s *testSuiteP1) TestIndexScan(c *C) {
func (s *testSuite8) TestIndexScan(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
Expand Down Expand Up @@ -2388,7 +2399,7 @@ func (s *testSuiteP2) TestHistoryRead(c *C) {
tk.MustQuery("select * from history_read order by a").Check(testkit.Rows("2 <nil>", "4 <nil>", "8 8", "9 9"))
}

func (s *testSuiteP2) TestLowResolutionTSORead(c *C) {
func (s *testSuite2) TestLowResolutionTSORead(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set @@autocommit=1")
tk.MustExec("use test")
Expand Down Expand Up @@ -2828,7 +2839,7 @@ func (s *testSuite1) TearDownTest(c *C) {
}
}

func (s *testSuite1) TestAddIndexPriority(c *C) {
func (s *testSuite2) TestAddIndexPriority(c *C) {
cli := &checkRequestClient{}
hijackClient := func(c tikv.Client) tikv.Client {
cli.Client = c
Expand Down Expand Up @@ -3955,6 +3966,24 @@ func (s *testSuite7) TearDownTest(c *C) {
}
}

type testSuite8 struct {
*baseTestSuite
}

func (s *testSuite8) TearDownTest(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
r := tk.MustQuery("show full tables")
for _, tb := range r.Rows() {
tableName := tb[0]
if tb[1] == "VIEW" {
tk.MustExec(fmt.Sprintf("drop view %v", tableName))
} else {
tk.MustExec(fmt.Sprintf("drop table %v", tableName))
}
}
}

func (s *testSuiteP2) TestStrToDateBuiltin(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustQuery(`select str_to_date('20190101','%Y%m%d%!') from dual`).Check(testkit.Rows("2019-01-01"))
Expand Down Expand Up @@ -4436,9 +4465,10 @@ func (s *testOOMSuite) TestDistSQLMemoryControl(c *C) {
}

func setOOMAction(action string) {
newConf := config.NewConfig()
old := config.GetGlobalConfig()
newConf := *old
newConf.OOMAction = action
config.StoreGlobalConfig(newConf)
config.StoreGlobalConfig(&newConf)
}

func (s *testSuite) TestOOMPanicAction(c *C) {
Expand Down
4 changes: 2 additions & 2 deletions executor/explain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (s *testSuite1) checkMemoryInfo(c *C, tk *testkit.TestKit, sql string) {
}
}

func (s *testSuite1) TestExplainAnalyzeExecutionInfo(c *C) {
func (s *testSuite2) TestExplainAnalyzeExecutionInfo(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (v int, k int, key(k))")
Expand Down Expand Up @@ -187,7 +187,7 @@ func (s *testSuite1) TestExplainAnalyzeExecutionInfo(c *C) {
tk.MustExec("drop table if exists lineitem")
}

func (s *testSuite1) checkExecutionInfo(c *C, tk *testkit.TestKit, sql string) {
func (s *testSuite2) checkExecutionInfo(c *C, tk *testkit.TestKit, sql string) {
executionInfoCol := 4
rows := tk.MustQuery(sql).Rows()
for _, row := range rows {
Expand Down
2 changes: 1 addition & 1 deletion executor/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/pingcap/tidb/util/testkit"
)

func (s *testSuite3) TestInsertOnDuplicateKey(c *C) {
func (s *testSuite8) TestInsertOnDuplicateKey(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down
Loading

0 comments on commit e1b43fa

Please sign in to comment.