Skip to content

Commit

Permalink
util/testutil: cleanup testutils depend on pingcap/check (pingcap#32662)
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun authored Feb 28, 2022
1 parent 9f1be5c commit 0c9b0c0
Show file tree
Hide file tree
Showing 34 changed files with 365 additions and 483 deletions.
2 changes: 1 addition & 1 deletion ddl/column_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestColumnChangeSuite(t *testing.T) {

func (s *testColumnChangeSuiteToVerify) SetupSuite() {
SetWaitTimeWhenErrorOccurred(1 * time.Microsecond)
s.store = testCreateStore(s.T(), "test_column_change")
s.store = createMockStore(s.T())
d, err := testNewDDLAndStart(
context.Background(),
WithStore(s.store),
Expand Down
2 changes: 1 addition & 1 deletion ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestColumnSuite(t *testing.T) {
}

func (s *testColumnSuiteToVerify) SetupSuite() {
s.store = testCreateStore(s.T(), "test_column")
s.store = createMockStore(s.T())
d, err := testNewDDLAndStart(
context.Background(),
WithStore(s.store),
Expand Down
8 changes: 1 addition & 7 deletions ddl/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,7 @@ func testNewDDLAndStart(ctx context.Context, options ...Option) (*ddl, error) {
return d, err
}

func testCreateStore(t *testing.T, name string) kv.Storage {
store, err := mockstore.NewMockStore()
require.NoError(t, err)
return store
}

func testCreateStoreT(t *testing.T, name string) kv.Storage {
func createMockStore(t *testing.T) kv.Storage {
store, err := mockstore.NewMockStore()
require.NoError(t, err)
return store
Expand Down
36 changes: 18 additions & 18 deletions ddl/ddl_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ import (
"github.com/pingcap/tidb/util/admin"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/testutil"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

type testDDLSuiteToVerify struct {
suite.Suite
testutil.CommonHandleSuite
}

func TestDDLSuite(t *testing.T) {
Expand Down Expand Up @@ -74,7 +72,7 @@ func (s *testDDLSerialSuiteToVerify) SetupSuite() {
}

func (s *testDDLSuiteToVerify) TestCheckOwner() {
store := testCreateStore(s.T(), "test_owner")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand All @@ -97,8 +95,10 @@ func (s *testDDLSuiteToVerify) TestCheckOwner() {
}

func (s *testDDLSuiteToVerify) TestNotifyDDLJob() {
store := testCreateStore(s.T(), "test_notify_job")
defer store.Close()
store := createMockStore(s.T())
defer func() {
require.NoError(s.T(), store.Close())
}()

getFirstNotificationAfterStartDDL := func(d *ddl) {
select {
Expand Down Expand Up @@ -189,7 +189,7 @@ func (s *testDDLSuiteToVerify) TestNotifyDDLJob() {

// testRunWorker tests no job is handled when the value of RunWorker is false.
func (s *testDDLSerialSuiteToVerify) testRunWorker() {
store := testCreateStore(s.T(), "test_run_worker")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down Expand Up @@ -229,7 +229,7 @@ func (s *testDDLSerialSuiteToVerify) testRunWorker() {
}

func (s *testDDLSuiteToVerify) TestSchemaError() {
store := testCreateStore(s.T(), "test_schema_error")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand All @@ -251,7 +251,7 @@ func (s *testDDLSuiteToVerify) TestSchemaError() {
}

func (s *testDDLSuiteToVerify) TestTableError() {
store := testCreateStore(s.T(), "test_table_error")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down Expand Up @@ -305,7 +305,7 @@ func (s *testDDLSuiteToVerify) TestTableError() {
}

func (s *testDDLSuiteToVerify) TestViewError() {
store := testCreateStore(s.T(), "test_view_error")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down Expand Up @@ -341,7 +341,7 @@ func (s *testDDLSuiteToVerify) TestViewError() {
}

func (s *testDDLSuiteToVerify) TestInvalidDDLJob() {
store := testCreateStore(s.T(), "test_invalid_ddl_job_type_error")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down Expand Up @@ -370,7 +370,7 @@ func (s *testDDLSuiteToVerify) TestInvalidDDLJob() {
}

func (s *testDDLSuiteToVerify) TestForeignKeyError() {
store := testCreateStore(s.T(), "test_foreign_key_error")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down Expand Up @@ -401,7 +401,7 @@ func (s *testDDLSuiteToVerify) TestForeignKeyError() {
}

func (s *testDDLSuiteToVerify) TestIndexError() {
store := testCreateStore(s.T(), "test_index_error")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down Expand Up @@ -450,7 +450,7 @@ func (s *testDDLSuiteToVerify) TestIndexError() {
}

func (s *testDDLSuiteToVerify) TestColumnError() {
store := testCreateStore(s.T(), "test_column_error")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down Expand Up @@ -511,7 +511,7 @@ func (s *testDDLSuiteToVerify) TestColumnError() {
}

func (s *testDDLSerialSuiteToVerify) TestAddBatchJobError() {
store := testCreateStore(s.T(), "test_add_batch_job_error")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down Expand Up @@ -830,7 +830,7 @@ func checkIdxVisibility(changedTable table.Table, idxName string, expected bool)
}

func (s *testDDLSerialSuiteToVerify) TestCancelJob() {
store := testCreateStore(s.T(), "test_cancel_job")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down Expand Up @@ -1457,7 +1457,7 @@ func (s *testDDLSuiteToVerify) TestIgnorableSpec() {
}

func (s *testDDLSuiteToVerify) TestBuildJobDependence() {
store := testCreateStore(s.T(), "test_set_job_relation")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down Expand Up @@ -1544,7 +1544,7 @@ func addDDLJob(t *testing.T, d *ddl, job *model.Job) {
}

func (s *testDDLSuiteToVerify) TestParallelDDL() {
store := testCreateStore(s.T(), "test_parallel_ddl")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down Expand Up @@ -1750,7 +1750,7 @@ func (s *testDDLSuiteToVerify) TestParallelDDL() {
}

func (s *testDDLSuiteToVerify) TestDDLPackageExecuteSQL() {
store := testCreateStore(s.T(), "test_run_sql")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down
2 changes: 1 addition & 1 deletion ddl/foreign_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestForeignKey(t *testing.T) {
t.Fatal(err)
}

store := testCreateStoreT(t, "test_foreign")
store := createMockStore(t)
defer func() {
err := store.Close()
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion ddl/index_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestIndexChangeSuite(t *testing.T) {
}

func (s *testIndexChangeSuiteToVerify) SetupSuite() {
s.store = testCreateStore(s.T(), "test_index_change")
s.store = createMockStore(s.T())
d, err := testNewDDLAndStart(
context.Background(),
WithStore(s.store),
Expand Down
2 changes: 1 addition & 1 deletion ddl/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

func ExportTestDropAndTruncatePartition(t *testing.T) {
store := testCreateStoreT(t, "test_store")
store := createMockStore(t)
defer func() {
err := store.Close()
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion ddl/placement_policy_ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func testCreatePlacementPolicy(t *testing.T, ctx sessionctx.Context, d *ddl, pol
}

func (s *testDDLSuiteToVerify) TestPlacementPolicyInUse() {
store := testCreateStore(s.T(), "test_placement_policy_in_use")
store := createMockStore(s.T())
defer func() {
err := store.Close()
require.NoError(s.T(), err)
Expand Down
Loading

0 comments on commit 0c9b0c0

Please sign in to comment.