forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtidb_test.go
145 lines (123 loc) · 3.01 KB
/
tidb_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2015 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.
// +build !race
package server
import (
"database/sql"
"time"
"github.com/ngaut/log"
. "github.com/pingcap/check"
"github.com/pingcap/tidb"
)
type TidbTestSuite struct {
tidbdrv *TiDBDriver
server *Server
}
var _ = Suite(new(TidbTestSuite))
func (ts *TidbTestSuite) SetUpSuite(c *C) {
log.SetLevelByString("error")
store, err := tidb.NewStore("memory:///tmp/tidb")
c.Assert(err, IsNil)
err = tidb.BootstrapSession(store)
c.Assert(err, IsNil)
ts.tidbdrv = NewTiDBDriver(store)
cfg := &Config{
Addr: ":4001",
LogLevel: "debug",
StatusAddr: ":10090",
ReportStatus: true,
}
server, err := NewServer(cfg, ts.tidbdrv)
c.Assert(err, IsNil)
ts.server = server
go ts.server.Run()
waitUntilServerOnline()
// Run this test here because parallel would affect the result of it.
runTestStmtCount(c)
defaultLoadDataBatchCnt = 3
}
func waitUntilServerOnline() {
for {
time.Sleep(time.Millisecond * 10)
db, err := sql.Open("mysql", dsn)
if err == nil {
db.Close()
break
}
}
}
func (ts *TidbTestSuite) TearDownSuite(c *C) {
if ts.server != nil {
ts.server.Close()
}
}
func (ts *TidbTestSuite) TestRegression(c *C) {
if regression {
c.Parallel()
runTestRegression(c, "Regression")
}
}
func (ts *TidbTestSuite) TestUint64(c *C) {
runTestPrepareResultFieldType(c)
}
func (ts *TidbTestSuite) TestSpecialType(c *C) {
c.Parallel()
runTestSpecialType(c)
}
func (ts *TidbTestSuite) TestPreparedString(c *C) {
c.Parallel()
runTestPreparedString(c)
}
func (ts *TidbTestSuite) TestLoadData(c *C) {
runTestLoadData(c)
}
func (ts *TidbTestSuite) TestConcurrentUpdate(c *C) {
runTestConcurrentUpdate(c)
}
func (ts *TidbTestSuite) TestErrorCode(c *C) {
runTestErrorCode(c)
}
func (ts *TidbTestSuite) TestAuth(c *C) {
runTestAuth(c)
}
func (ts *TidbTestSuite) TestIssues(c *C) {
runTestIssues(c)
}
func (ts *TidbTestSuite) TestResultFieldTableIsNull(c *C) {
c.Parallel()
runTestResultFieldTableIsNull(c)
}
func (ts *TidbTestSuite) TestStatusAPI(c *C) {
runTestStatusAPI(c)
}
func (ts *TidbTestSuite) TestMultiStatements(c *C) {
c.Parallel()
runTestMultiStatements(c)
}
func (ts *TidbTestSuite) TestSocket(c *C) {
c.Parallel()
cfg := &Config{
LogLevel: "debug",
StatusAddr: ":10091",
Socket: "/tmp/tidbtest.sock",
}
server, err := NewServer(cfg, ts.tidbdrv)
c.Assert(err, IsNil)
go server.Run()
time.Sleep(time.Millisecond * 100)
tcpDsn := dsn
dsn = "root@unix(/tmp/tidbtest.sock)/test?strict=true"
runTestRegression(c, "SocketRegression")
dsn = tcpDsn
server.Close()
}