Skip to content

Commit

Permalink
*: check more errors in test. (#9859)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiekeyi98 authored Mar 24, 2019
1 parent 9251724 commit 5ed3553
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 34 deletions.
8 changes: 5 additions & 3 deletions kv/buffer_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ func (s testBufferStoreSuite) TestSaveTo(c *C) {
c.Check(err, IsNil)
buf.Reset()
}
bs.Set(Key("novalue"), nil)
err := bs.Set(Key("novalue"), []byte("novalue"))
c.Check(err, IsNil)

mutator := NewMemDbBuffer(DefaultTxnMembufCap)
err := bs.SaveTo(mutator)
err = bs.SaveTo(mutator)
c.Check(err, IsNil)

iter, err := mutator.Iter(nil, nil)
c.Check(err, IsNil)
for iter.Valid() {
cmp := bytes.Compare(iter.Key(), iter.Value())
c.Check(cmp, Equals, 0)
iter.Next()
err = iter.Next()
c.Check(err, IsNil)
}
}
6 changes: 4 additions & 2 deletions kv/mem_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,17 @@ func (s *testKVSuite) TestNewIteratorMin(c *C) {
}
for _, buffer := range s.bs {
for _, kv := range kvs {
buffer.Set([]byte(kv.key), []byte(kv.value))
err := buffer.Set([]byte(kv.key), []byte(kv.value))
c.Assert(err, IsNil)
}

cnt := 0
it, err := buffer.Iter(nil, nil)
c.Assert(err, IsNil)
for it.Valid() {
cnt++
it.Next()
err := it.Next()
c.Assert(err, IsNil)
}
c.Assert(cnt, Equals, 6)

Expand Down
15 changes: 10 additions & 5 deletions kv/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func (s testMockSuite) TestInterface(c *C) {
version, err := storage.CurrentVersion()
c.Check(err, IsNil)
snapshot, err := storage.GetSnapshot(version)
snapshot.BatchGet([]Key{Key("abc"), Key("def")})
c.Check(err, IsNil)
_, err = snapshot.BatchGet([]Key{Key("abc"), Key("def")})
c.Check(err, IsNil)

transaction, err := storage.Begin()
Expand All @@ -45,10 +46,14 @@ func (s testMockSuite) TestInterface(c *C) {
transaction.StartTS()
transaction.DelOption(Option(23))
if transaction.IsReadOnly() {
transaction.Get(Key("lock"))
transaction.Set(Key("lock"), []byte{})
transaction.Iter(Key("lock"), nil)
transaction.IterReverse(Key("lock"))
_, err = transaction.Get(Key("lock"))
c.Check(err, IsNil)
err = transaction.Set(Key("lock"), []byte{})
c.Check(err, IsNil)
_, err = transaction.Iter(Key("lock"), nil)
c.Check(err, IsNil)
_, err = transaction.IterReverse(Key("lock"))
c.Check(err, IsNil)
}
transaction.Commit(context.Background())

Expand Down
50 changes: 33 additions & 17 deletions kv/union_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,42 @@ func (s *testUnionStoreSuite) SetUpTest(c *C) {

func (s *testUnionStoreSuite) TestGetSet(c *C) {
defer testleak.AfterTest(c)()
s.store.Set([]byte("1"), []byte("1"))
err := s.store.Set([]byte("1"), []byte("1"))
c.Assert(err, IsNil)
v, err := s.us.Get([]byte("1"))
c.Assert(err, IsNil)
c.Assert(v, BytesEquals, []byte("1"))
s.us.Set([]byte("1"), []byte("2"))
err = s.us.Set([]byte("1"), []byte("2"))
c.Assert(err, IsNil)
v, err = s.us.Get([]byte("1"))
c.Assert(err, IsNil)
c.Assert(v, BytesEquals, []byte("2"))
}

func (s *testUnionStoreSuite) TestDelete(c *C) {
defer testleak.AfterTest(c)()
s.store.Set([]byte("1"), []byte("1"))
err := s.us.Delete([]byte("1"))
err := s.store.Set([]byte("1"), []byte("1"))
c.Assert(err, IsNil)
err = s.us.Delete([]byte("1"))
c.Assert(err, IsNil)
_, err = s.us.Get([]byte("1"))
c.Assert(IsErrNotFound(err), IsTrue)

s.us.Set([]byte("1"), []byte("2"))
err = s.us.Set([]byte("1"), []byte("2"))
c.Assert(err, IsNil)
v, err := s.us.Get([]byte("1"))
c.Assert(err, IsNil)
c.Assert(v, BytesEquals, []byte("2"))
}

func (s *testUnionStoreSuite) TestSeek(c *C) {
defer testleak.AfterTest(c)()
s.store.Set([]byte("1"), []byte("1"))
s.store.Set([]byte("2"), []byte("2"))
s.store.Set([]byte("3"), []byte("3"))
err := s.store.Set([]byte("1"), []byte("1"))
c.Assert(err, IsNil)
err = s.store.Set([]byte("2"), []byte("2"))
c.Assert(err, IsNil)
err = s.store.Set([]byte("3"), []byte("3"))
c.Assert(err, IsNil)

iter, err := s.us.Iter(nil, nil)
c.Assert(err, IsNil)
Expand All @@ -71,22 +78,27 @@ func (s *testUnionStoreSuite) TestSeek(c *C) {
c.Assert(err, IsNil)
checkIterator(c, iter, [][]byte{[]byte("2"), []byte("3")}, [][]byte{[]byte("2"), []byte("3")})

s.us.Set([]byte("4"), []byte("4"))
err = s.us.Set([]byte("4"), []byte("4"))
c.Assert(err, IsNil)
iter, err = s.us.Iter([]byte("2"), nil)
c.Assert(err, IsNil)
checkIterator(c, iter, [][]byte{[]byte("2"), []byte("3"), []byte("4")}, [][]byte{[]byte("2"), []byte("3"), []byte("4")})

s.us.Delete([]byte("3"))
err = s.us.Delete([]byte("3"))
c.Assert(err, IsNil)
iter, err = s.us.Iter([]byte("2"), nil)
c.Assert(err, IsNil)
checkIterator(c, iter, [][]byte{[]byte("2"), []byte("4")}, [][]byte{[]byte("2"), []byte("4")})
}

func (s *testUnionStoreSuite) TestIterReverse(c *C) {
defer testleak.AfterTest(c)()
s.store.Set([]byte("1"), []byte("1"))
s.store.Set([]byte("2"), []byte("2"))
s.store.Set([]byte("3"), []byte("3"))
err := s.store.Set([]byte("1"), []byte("1"))
c.Assert(err, IsNil)
err = s.store.Set([]byte("2"), []byte("2"))
c.Assert(err, IsNil)
err = s.store.Set([]byte("3"), []byte("3"))
c.Assert(err, IsNil)

iter, err := s.us.IterReverse(nil)
c.Assert(err, IsNil)
Expand All @@ -96,21 +108,25 @@ func (s *testUnionStoreSuite) TestIterReverse(c *C) {
c.Assert(err, IsNil)
checkIterator(c, iter, [][]byte{[]byte("2"), []byte("1")}, [][]byte{[]byte("2"), []byte("1")})

s.us.Set([]byte("0"), []byte("0"))
err = s.us.Set([]byte("0"), []byte("0"))
c.Assert(err, IsNil)
iter, err = s.us.IterReverse([]byte("3"))
c.Assert(err, IsNil)
checkIterator(c, iter, [][]byte{[]byte("2"), []byte("1"), []byte("0")}, [][]byte{[]byte("2"), []byte("1"), []byte("0")})

s.us.Delete([]byte("1"))
err = s.us.Delete([]byte("1"))
c.Assert(err, IsNil)
iter, err = s.us.IterReverse([]byte("3"))
c.Assert(err, IsNil)
checkIterator(c, iter, [][]byte{[]byte("2"), []byte("0")}, [][]byte{[]byte("2"), []byte("0")})
}

func (s *testUnionStoreSuite) TestLazyConditionCheck(c *C) {
defer testleak.AfterTest(c)()
s.store.Set([]byte("1"), []byte("1"))
s.store.Set([]byte("2"), []byte("2"))
err := s.store.Set([]byte("1"), []byte("1"))
c.Assert(err, IsNil)
err = s.store.Set([]byte("2"), []byte("2"))
c.Assert(err, IsNil)

v, err := s.us.Get([]byte("1"))
c.Assert(err, IsNil)
Expand Down
3 changes: 2 additions & 1 deletion kv/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func (s testUtilsSuite) TestIncInt64(c *C) {
c.Check(err, IsNil)
c.Check(v, Equals, int64(11))

mb.Set(key, []byte("not int"))
err = mb.Set(key, []byte("not int"))
c.Check(err, IsNil)
_, err = IncInt64(mb, key, 1)
c.Check(err, NotNil)
}
Expand Down
18 changes: 12 additions & 6 deletions sessionctx/variable/varsutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,34 +97,40 @@ func (s *testVarsutilSuite) TestVarsutil(c *C) {
v := NewSessionVars()
v.GlobalVarsAccessor = NewMockGlobalAccessor()

SetSessionSystemVar(v, "autocommit", types.NewStringDatum("1"))
err := SetSessionSystemVar(v, "autocommit", types.NewStringDatum("1"))
c.Assert(err, IsNil)
val, err := GetSessionSystemVar(v, "autocommit")
c.Assert(err, IsNil)
c.Assert(val, Equals, "1")
c.Assert(SetSessionSystemVar(v, "autocommit", types.Datum{}), NotNil)

// 0 converts to OFF
SetSessionSystemVar(v, "foreign_key_checks", types.NewStringDatum("0"))
err = SetSessionSystemVar(v, "foreign_key_checks", types.NewStringDatum("0"))
c.Assert(err, IsNil)
val, err = GetSessionSystemVar(v, "foreign_key_checks")
c.Assert(err, IsNil)
c.Assert(val, Equals, "OFF")

// 1/ON is not supported (generates a warning and sets to OFF)
SetSessionSystemVar(v, "foreign_key_checks", types.NewStringDatum("1"))
err = SetSessionSystemVar(v, "foreign_key_checks", types.NewStringDatum("1"))
c.Assert(err, IsNil)
val, err = GetSessionSystemVar(v, "foreign_key_checks")
c.Assert(err, IsNil)
c.Assert(val, Equals, "OFF")

SetSessionSystemVar(v, "sql_mode", types.NewStringDatum("strict_trans_tables"))
err = SetSessionSystemVar(v, "sql_mode", types.NewStringDatum("strict_trans_tables"))
c.Assert(err, IsNil)
val, err = GetSessionSystemVar(v, "sql_mode")
c.Assert(err, IsNil)
c.Assert(val, Equals, "STRICT_TRANS_TABLES")
c.Assert(v.StrictSQLMode, IsTrue)
SetSessionSystemVar(v, "sql_mode", types.NewStringDatum(""))
c.Assert(v.StrictSQLMode, IsFalse)

SetSessionSystemVar(v, "character_set_connection", types.NewStringDatum("utf8"))
SetSessionSystemVar(v, "collation_connection", types.NewStringDatum("utf8_general_ci"))
err = SetSessionSystemVar(v, "character_set_connection", types.NewStringDatum("utf8"))
c.Assert(err, IsNil)
err = SetSessionSystemVar(v, "collation_connection", types.NewStringDatum("utf8_general_ci"))
c.Assert(err, IsNil)
charset, collation := v.GetCharsetInfo()
c.Assert(charset, Equals, "utf8")
c.Assert(collation, Equals, "utf8_general_ci")
Expand Down

0 comments on commit 5ed3553

Please sign in to comment.