Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl/ddl_test.go: refactor testNewDDLAndStart to return error #29964

Merged
merged 6 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ddl/column_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ type testColumnChangeSuite struct {
func (s *testColumnChangeSuite) SetUpSuite(c *C) {
SetWaitTimeWhenErrorOccurred(1 * time.Microsecond)
s.store = testCreateStore(c, "test_column_change")
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
defer func() {
err := d.Stop()
c.Assert(err, IsNil)
Expand All @@ -67,20 +67,20 @@ func (s *testColumnChangeSuite) TearDownSuite(c *C) {
}

func (s *testColumnChangeSuite) TestColumnChange(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
defer func() {
err := d.Stop()
c.Assert(err, IsNil)
}()
// create table t (c1 int, c2 int);
tblInfo := testTableInfo(c, d, "t", 2)
ctx := testNewContext(d)
err := ctx.NewTxn(context.Background())
err = ctx.NewTxn(context.Background())
c.Assert(err, IsNil)
testCreateTable(c, ctx, d, s.dbInfo, tblInfo)
// insert t values (1, 2);
Expand Down Expand Up @@ -163,12 +163,12 @@ func (s *testColumnChangeSuite) TestColumnChange(c *C) {
}

func (s *testColumnChangeSuite) TestModifyAutoRandColumnWithMetaKeyChanged(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
defer func() {
err := d.Stop()
c.Assert(err, IsNil)
Expand Down
42 changes: 21 additions & 21 deletions ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ type testColumnSuite struct {

func (s *testColumnSuite) SetUpSuite(c *C) {
s.store = testCreateStore(c, "test_column")
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)

s.dbInfo = testSchemaInfo(c, d, "test_column")
testCreateSchema(c, testNewContext(d), d, s.dbInfo)
Expand Down Expand Up @@ -185,12 +185,12 @@ func testDropColumns(c *C, ctx sessionctx.Context, d *ddl, dbInfo *model.DBInfo,
}

func (s *testColumnSuite) TestColumnBasic(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
defer func() {
err := d.Stop()
c.Assert(err, IsNil)
Expand All @@ -208,7 +208,7 @@ func (s *testColumnSuite) TestColumnBasic(c *C) {
c.Assert(err, IsNil)
}

err := ctx.NewTxn(context.Background())
err = ctx.NewTxn(context.Background())
c.Assert(err, IsNil)

i := int64(0)
Expand Down Expand Up @@ -836,16 +836,16 @@ func (s *testColumnSuite) testGetColumn(t table.Table, name string, isExist bool
}

func (s *testColumnSuite) TestAddColumn(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
tblInfo := testTableInfo(c, d, "t", 3)
ctx := testNewContext(d)

err := ctx.NewTxn(context.Background())
err = ctx.NewTxn(context.Background())
c.Assert(err, IsNil)

testCreateTable(c, ctx, d, s.dbInfo, tblInfo)
Expand Down Expand Up @@ -924,16 +924,16 @@ func (s *testColumnSuite) TestAddColumn(c *C) {
}

func (s *testColumnSuite) TestAddColumns(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
tblInfo := testTableInfo(c, d, "t", 3)
ctx := testNewContext(d)

err := ctx.NewTxn(context.Background())
err = ctx.NewTxn(context.Background())
c.Assert(err, IsNil)

testCreateTable(c, ctx, d, s.dbInfo, tblInfo)
Expand Down Expand Up @@ -1009,16 +1009,16 @@ func (s *testColumnSuite) TestAddColumns(c *C) {
}

func (s *testColumnSuite) TestDropColumn(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
tblInfo := testTableInfo(c, d, "t2", 4)
ctx := testNewContext(d)

err := ctx.NewTxn(context.Background())
err = ctx.NewTxn(context.Background())
c.Assert(err, IsNil)

testCreateTable(c, ctx, d, s.dbInfo, tblInfo)
Expand Down Expand Up @@ -1085,16 +1085,16 @@ func (s *testColumnSuite) TestDropColumn(c *C) {
}

func (s *testColumnSuite) TestDropColumns(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
tblInfo := testTableInfo(c, d, "t2", 4)
ctx := testNewContext(d)

err := ctx.NewTxn(context.Background())
err = ctx.NewTxn(context.Background())
c.Assert(err, IsNil)

testCreateTable(c, ctx, d, s.dbInfo, tblInfo)
Expand Down Expand Up @@ -1154,12 +1154,12 @@ func (s *testColumnSuite) TestDropColumns(c *C) {
}

func (s *testColumnSuite) TestModifyColumn(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
ctx := testNewContext(d)

defer func() {
Expand Down Expand Up @@ -1222,12 +1222,12 @@ func (s *testColumnSuite) TestFieldCase(c *C) {
}

func (s *testColumnSuite) TestAutoConvertBlobTypeByLength(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
// Close the customized ddl(worker goroutine included) after the test is finished, otherwise, it will
// cause go routine in TiDB leak test.
defer func() {
Expand Down
6 changes: 2 additions & 4 deletions ddl/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,14 @@ func TestT(t *testing.T) {
testleak.AfterTestT(t)()
}

func testNewDDLAndStart(ctx context.Context, c *C, options ...Option) *ddl {
func testNewDDLAndStart(ctx context.Context, options ...Option) (*ddl, error) {
// init infoCache and a stub infoSchema
ic := infoschema.NewCache(2)
ic.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0)
options = append(options, WithInfoCache(ic))
d := newDDL(ctx, options...)
err := d.Start(nil)
c.Assert(err, IsNil)

return d
return d, err
}

func testCreateStore(c *C, name string) kv.Storage {
Expand Down
Loading