diff --git a/util/kvencoder/kv_encoder_test.go b/util/kvencoder/kv_encoder_test.go index e7b8349d081ec..4b93e0446e0b5 100644 --- a/util/kvencoder/kv_encoder_test.go +++ b/util/kvencoder/kv_encoder_test.go @@ -140,14 +140,9 @@ func (s *testKvEncoderSuite) runTestSQL(c *C, tkExpect *testkit.TestKit, encoder } func (s *testKvEncoderSuite) TestCustomDatabaseHandle(c *C) { - store, dom, err := newStoreWithBootstrap() - c.Assert(err, IsNil) - defer store.Close() - defer dom.Close() - dbname := "tidb" - tkExpect := testkit.NewTestKit(c, store) + tkExpect := testkit.NewTestKit(c, s.store) tkExpect.MustExec("create database if not exists " + dbname) tkExpect.MustExec("use " + dbname) @@ -171,18 +166,14 @@ func (s *testKvEncoderSuite) TestCustomDatabaseHandle(c *C) { } func (s *testKvEncoderSuite) TestInsertPkIsHandle(c *C) { - store, dom, err := newStoreWithBootstrap() - c.Assert(err, IsNil) - defer store.Close() - defer dom.Close() - - tkExpect := testkit.NewTestKit(c, store) + tkExpect := testkit.NewTestKit(c, s.store) tkExpect.MustExec("use test") var tableID int64 = 1 encoder, err := New("test", nil) c.Assert(err, IsNil) defer encoder.Close() + tkExpect.MustExec("drop table if exists t") schemaSQL := "create table t(id int auto_increment, a char(10), primary key(id))" tkExpect.MustExec(schemaSQL) err = encoder.ExecDDLSQL(schemaSQL) @@ -200,6 +191,7 @@ func (s *testKvEncoderSuite) TestInsertPkIsHandle(c *C) { s.runTestSQL(c, tkExpect, encoder, sqls, tableID) + tkExpect.MustExec("drop table if exists t1") schemaSQL = "create table t1(id int auto_increment, a char(10), primary key(id), key a_idx(a))" tkExpect.MustExec(schemaSQL) err = encoder.ExecDDLSQL(schemaSQL) @@ -227,6 +219,7 @@ func (s *testKvEncoderSuite) TestInsertPkIsHandle(c *C) { ` tableID = 3 + tkExpect.MustExec("drop table if exists t2") tkExpect.MustExec(schemaSQL) err = encoder.ExecDDLSQL(schemaSQL) c.Assert(err, IsNil) @@ -250,11 +243,6 @@ func makePrepareTestCase(sql, formatSQL string, param ...interface{}) prepareTes } func (s *testKvEncoderSuite) TestPrepareEncode(c *C) { - store, dom, err := newStoreWithBootstrap() - c.Assert(err, IsNil) - defer store.Close() - defer dom.Close() - alloc := NewAllocator() encoder, err := New("test", alloc) c.Assert(err, IsNil) @@ -299,12 +287,7 @@ func (s *testKvEncoderSuite) comparePrepareAndNormalEncode(c *C, alloc autoid.Al } func (s *testKvEncoderSuite) TestInsertPkIsNotHandle(c *C) { - store, dom, err := newStoreWithBootstrap() - c.Assert(err, IsNil) - defer store.Close() - defer dom.Close() - - tkExpect := testkit.NewTestKit(c, store) + tkExpect := testkit.NewTestKit(c, s.store) tkExpect.MustExec("use test") var tableID int64 = 1 @@ -312,6 +295,7 @@ func (s *testKvEncoderSuite) TestInsertPkIsNotHandle(c *C) { c.Assert(err, IsNil) defer encoder.Close() + tkExpect.MustExec("drop table if exists t") schemaSQL := `create table t( id varchar(20), a char(10), @@ -333,12 +317,7 @@ func (s *testKvEncoderSuite) TestInsertPkIsNotHandle(c *C) { } func (s *testKvEncoderSuite) TestRetryWithAllocator(c *C) { - store, dom, err := newStoreWithBootstrap() - c.Assert(err, IsNil) - defer store.Close() - defer dom.Close() - - tk := testkit.NewTestKit(c, store) + tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") alloc := NewAllocator() @@ -347,6 +326,7 @@ func (s *testKvEncoderSuite) TestRetryWithAllocator(c *C) { c.Assert(err, IsNil) defer encoder.Close() + tk.MustExec("drop table if exists t") schemaSQL := `create table t( id int auto_increment, a char(10), @@ -388,6 +368,7 @@ func (s *testKvEncoderSuite) TestRetryWithAllocator(c *C) { c.Assert(bytes.Compare(row.Val, retryKvPairs[i].Val), Equals, 0, Commentf(sql)) } + tk.MustExec("drop table if exists t1") schemaSQL = `create table t1( id int auto_increment, a char(10), @@ -424,12 +405,7 @@ func (s *testKvEncoderSuite) TestRetryWithAllocator(c *C) { } func (s *testKvEncoderSuite) TestAllocatorRebase(c *C) { - store, dom, err := newStoreWithBootstrap() - c.Assert(err, IsNil) - defer store.Close() - defer dom.Close() - - tk := testkit.NewTestKit(c, store) + tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") alloc := NewAllocator() var tableID int64 = 1