diff --git a/planner/core/indexmerge_test.go b/planner/core/indexmerge_test.go index c69215b52a173..13827af5d1f23 100644 --- a/planner/core/indexmerge_test.go +++ b/planner/core/indexmerge_test.go @@ -16,42 +16,17 @@ package core import ( "context" + "testing" - . "github.com/pingcap/check" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/parser" "github.com/pingcap/tidb/parser/model" "github.com/pingcap/tidb/planner/util" - "github.com/pingcap/tidb/sessionctx" + "github.com/pingcap/tidb/testkit/testdata" "github.com/pingcap/tidb/util/hint" - "github.com/pingcap/tidb/util/testleak" - "github.com/pingcap/tidb/util/testutil" + "github.com/stretchr/testify/require" ) -var _ = Suite(&testIndexMergeSuite{}) - -type testIndexMergeSuite struct { - *parser.Parser - - is infoschema.InfoSchema - ctx sessionctx.Context - - testdata testutil.TestData -} - -func (s *testIndexMergeSuite) SetUpSuite(c *C) { - s.is = infoschema.MockInfoSchema([]*model.TableInfo{MockSignedTable(), MockView()}) - s.ctx = MockContext() - s.Parser = parser.New() - var err error - s.testdata, err = testutil.LoadTestSuiteData("testdata", "index_merge_suite") - c.Assert(err, IsNil) -} - -func (s *testIndexMergeSuite) TearDownSuite(c *C) { - c.Assert(s.testdata.GenerateOutputIfNeeded(), IsNil) -} - func getIndexMergePathDigest(paths []*util.AccessPath, startIndex int) string { if len(paths) == startIndex { return "[]" @@ -82,31 +57,34 @@ func getIndexMergePathDigest(paths []*util.AccessPath, startIndex int) string { return idxMergeDisgest } -func (s *testIndexMergeSuite) TestIndexMergePathGeneration(c *C) { - defer testleak.AfterTest(c)() +func TestIndexMergePathGeneration(t *testing.T) { + t.Parallel() var input, output []string - s.testdata.GetTestCases(c, &input, &output) + indexMergeSuiteData.GetTestCases(t, &input, &output) ctx := context.TODO() + sctx := MockContext() + is := infoschema.MockInfoSchema([]*model.TableInfo{MockSignedTable(), MockView()}) + + parser := parser.New() + for i, tc := range input { - comment := Commentf("case:%v sql:%s", i, tc) - stmt, err := s.ParseOneStmt(tc, "", "") - c.Assert(err, IsNil, comment) - err = Preprocess(s.ctx, stmt, WithPreprocessorReturn(&PreprocessorReturn{InfoSchema: s.is})) - c.Assert(err, IsNil) - builder, _ := NewPlanBuilder().Init(MockContext(), s.is, &hint.BlockHintProcessor{}) + stmt, err := parser.ParseOneStmt(tc, "", "") + require.NoErrorf(t, err, "case:%v sql:%s", i, tc) + err = Preprocess(sctx, stmt, WithPreprocessorReturn(&PreprocessorReturn{InfoSchema: is})) + require.NoError(t, err) + builder, _ := NewPlanBuilder().Init(MockContext(), is, &hint.BlockHintProcessor{}) p, err := builder.Build(ctx, stmt) if err != nil { - s.testdata.OnRecord(func() { + testdata.OnRecord(func() { output[i] = err.Error() }) - c.Assert(err.Error(), Equals, output[i], comment) + require.Equal(t, output[i], err.Error(), "case:%v sql:%s", i, tc) continue } - c.Assert(err, IsNil) + require.NoError(t, err) p, err = logicalOptimize(ctx, builder.optFlag, p.(LogicalPlan)) - c.Assert(err, IsNil) + require.NoError(t, err) lp := p.(LogicalPlan) - c.Assert(err, IsNil) var ds *DataSource for ds == nil { switch v := lp.(type) { @@ -119,11 +97,11 @@ func (s *testIndexMergeSuite) TestIndexMergePathGeneration(c *C) { ds.ctx.GetSessionVars().SetEnableIndexMerge(true) idxMergeStartIndex := len(ds.possibleAccessPaths) _, err = lp.recursiveDeriveStats(nil) - c.Assert(err, IsNil) + require.NoError(t, err) result := getIndexMergePathDigest(ds.possibleAccessPaths, idxMergeStartIndex) - s.testdata.OnRecord(func() { + testdata.OnRecord(func() { output[i] = result }) - c.Assert(result, Equals, output[i], comment) + require.Equalf(t, output[i], result, "case:%v sql:%s", i, tc) } } diff --git a/planner/core/main_test.go b/planner/core/main_test.go index df250425aaaf4..236d154ff8934 100644 --- a/planner/core/main_test.go +++ b/planner/core/main_test.go @@ -24,7 +24,8 @@ import ( "go.uber.org/goleak" ) -var testDataMap = make(testdata.BookKeeper, 1) +var testDataMap = make(testdata.BookKeeper, 2) +var indexMergeSuiteData testdata.TestData func TestMain(m *testing.M) { testbridge.WorkaroundGoCheckFlags() @@ -32,6 +33,8 @@ func TestMain(m *testing.M) { flag.Parse() testDataMap.LoadTestSuiteData("testdata", "integration_partition_suite") + testDataMap.LoadTestSuiteData("testdata", "index_merge_suite") + indexMergeSuiteData = testDataMap["index_merge_suite"] opts := []goleak.Option{ goleak.IgnoreTopFunction("go.etcd.io/etcd/pkg/logutil.(*MergeLogger).outputLoop"),