forked from talent-plan/tinysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
isolation_test.go
74 lines (65 loc) · 2.22 KB
/
isolation_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2018 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package session_test
import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/store/mockstore/mocktikv"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testleak"
)
var _ = Suite(&testIsolationSuite{})
type testIsolationSuite struct {
cluster *mocktikv.Cluster
mvccStore mocktikv.MVCCStore
store kv.Storage
dom *domain.Domain
}
func (s *testIsolationSuite) SetUpSuite(c *C) {
testleak.BeforeTest()
s.cluster = mocktikv.NewCluster()
mocktikv.BootstrapWithSingleStore(s.cluster)
s.mvccStore = mocktikv.MustNewMVCCStore()
store, err := mockstore.NewMockTikvStore(
mockstore.WithCluster(s.cluster),
mockstore.WithMVCCStore(s.mvccStore),
)
c.Assert(err, IsNil)
s.store = store
session.SetSchemaLease(0)
session.DisableStats4Test()
s.dom, err = session.BootstrapSession(s.store)
c.Assert(err, IsNil)
}
func (s *testIsolationSuite) TearDownSuite(c *C) {
s.dom.Close()
s.store.Close()
testleak.AfterTest(c)()
}
func (s *testIsolationSuite) TestA3Phantom(c *C) {
session1 := testkit.NewTestKitWithInit(c, s.store)
session2 := testkit.NewTestKitWithInit(c, s.store)
session1.MustExec("drop table if exists x;")
session1.MustExec("create table x (id int primary key, c int);")
session1.MustExec("insert into x values(1, 1);")
session1.MustExec("begin;")
session2.MustExec("begin;")
session2.MustQuery("select c from x where id < 5;").Check(testkit.Rows("1"))
session1.MustExec("insert into x values(2, 1);")
session1.MustExec("commit;")
session2.MustQuery("select c from x where id < 5;").Check(testkit.Rows("1"))
session2.MustExec("commit;")
}