forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests.sh
executable file
·288 lines (258 loc) · 8.06 KB
/
run-tests.sh
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/env bash
# Copyright 2019 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,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
TIDB_TEST_STORE_NAME=$TIDB_TEST_STORE_NAME
TIKV_PATH=$TIKV_PATH
build=1
mysql_tester="./mysql_tester"
tidb_server=""
portgenerator=""
mysql_tester_log="./integration-test.out"
tests=""
record=0
record_case=""
stats="s"
collation_opt=2
set -eu
trap 'set +e; PIDS=$(jobs -p); [ -n "$PIDS" ] && kill -9 $PIDS' EXIT
# make tests stable time zone wise
export TZ="Asia/Shanghai"
function help_message()
{
echo "Usage: $0 [options]
-h: Print this help message.
-d <y|Y|n|N|b|B>: \"y\" or \"Y\" for only enabling the new collation during test.
\"n\" or \"N\" for only disabling the new collation during test.
\"b\" or \"B\" for both tests [default].
Enable/Disable the new collation during the integration test.
-s <tidb-server-path>: Use tidb-server in <tidb-server-path> for testing.
eg. \"./run-tests.sh -s ./integrationtest_tidb-server\"
-b <y|Y|n|N>: \"y\" or \"Y\" for building test binaries [default \"y\" if this option is not specified].
\"n\" or \"N\" for not to build.
The building of tidb-server will be skiped if \"-s <tidb-server-path>\" is provided.
The building of portgenerator will be skiped if \"-s <portgenerator-path>\" is provided.
-r <test-name>|all: Run tests in file \"t/<test-name>.test\" and record result to file \"r/<test-name>.result\".
\"all\" for running all tests and record their results.
-t <test-name>: Run tests in file \"t/<test-name>.test\".
This option will be ignored if \"-r <test-name>\" is provided.
Run all tests if this option is not provided.
-p <portgenerator-path>: Use port generator in <portgenerator-path> for generating port numbers.
"
}
function build_portgenerator()
{
portgenerator="./portgenerator"
echo "building portgenerator binary: $portgenerator"
rm -rf $portgenerator
GO111MODULE=on go build -o $portgenerator github.com/pingcap/tidb/cmd/portgenerator
}
function build_tidb_server()
{
tidb_server="./integrationtest_tidb-server"
echo "building tidb-server binary: $tidb_server"
rm -rf $tidb_server
if [ "${TIDB_TEST_STORE_NAME}" = "tikv" ]; then
GO111MODULE=on go build -o $tidb_server github.com/pingcap/tidb/tidb-server
else
GO111MODULE=on go build -race -o $tidb_server github.com/pingcap/tidb/tidb-server
fi
}
function build_mysql_tester()
{
echo "building mysql-tester binary: $mysql_tester"
rm -rf $mysql_tester
GOBIN=$PWD go install github.com/defined2014/mysql-tester/src@1da6225968e19999d28be4d06c357b9378df8b78
mv src mysql_tester
}
function extract_stats()
{
echo "extracting statistics: $stats"
rm -rf $stats
unzip -qq s.zip
}
while getopts "t:s:r:b:d:c:i:h:p" opt; do
case $opt in
t)
tests="$OPTARG"
;;
s)
tidb_server="$OPTARG"
;;
r)
record=1
record_case="$OPTARG"
;;
b)
case $OPTARG in
y|Y)
build=1
;;
n|N)
build=0
;;
*)
help_messge 1>&2
exit 1
;;
esac
;;
d)
case $OPTARG in
y|Y)
collation_opt=1
;;
n|N)
collation_opt=0
;;
*)
help_messge 1>&2
exit 1
;;
esac
;;
h)
help_message
exit 0
;;
p)
portgenerator="$OPTARG"
;;
*)
help_message 1>&2
exit 1
;;
esac
done
extract_stats
if [ $build -eq 1 ]; then
if [ -z "$tidb_server" ]; then
build_tidb_server
else
echo "skip building tidb-server, using existing binary: $tidb_server"
fi
if [[ -z "$portgenerator" ]]; then
build_portgenerator
else
echo "skip building portgenerator, using existing binary: $portgenerator"
fi
build_mysql_tester
else
if [ -z "$tidb_server" ]; then
tidb_server="./integrationtest_tidb-server"
if [[ ! -f "$tidb_server" ]]; then
build_tidb_server
else
echo "skip building tidb-server, using existing binary: $tidb_server"
fi
fi
if [ -z "$mysql_tester" ]; then
mysql_tester="./mysql_tester"
if [[ ! -f "$mysql_tester" ]]; then
build_mysql_tester
else
echo "skip building mysql-tester, using existing binary: $mysql_tester"
fi
fi
if [ -z "$portgenerator" ]; then
portgenerator="./portgenerator"
if [[ ! -f "$portgenerator" ]]; then
build_portgenerator
else
echo "skip building portgenerator, using existing binary: $portgenerator"
fi
fi
fi
rm -rf $mysql_tester_log
ports=()
for port in $($portgenerator -count 2); do
ports+=("$port")
done
port=${ports[0]}
status=${ports[1]}
function start_tidb_server()
{
config_file="config.toml"
if [[ $enabled_new_collation = 0 ]]; then
config_file="disable_new_collation.toml"
fi
echo "start tidb-server, log file: $mysql_tester_log"
if [ "${TIDB_TEST_STORE_NAME}" = "tikv" ]; then
$tidb_server -P "$port" -status "$status" -config $config_file -store tikv -path "${TIKV_PATH}" > $mysql_tester_log 2>&1 &
SERVER_PID=$!
else
$tidb_server -P "$port" -status "$status" -config $config_file -store unistore -path "" > $mysql_tester_log 2>&1 &
SERVER_PID=$!
fi
echo "tidb-server(PID: $SERVER_PID) started"
}
function run_mysql_tester()
{
coll_disabled="false"
coll_msg="enabled new collation"
if [[ $enabled_new_collation = 0 ]]; then
coll_disabled="true"
coll_msg="disabled new collation"
fi
if [ $record -eq 1 ]; then
if [ "$record_case" = 'all' ]; then
echo "record all cases"
$mysql_tester -port "$port" --collation-disable=$coll_disabled --record
else
echo "record result for case: \"$record_case\""
$mysql_tester -port "$port" --collation-disable=$coll_disabled --record $record_case
fi
else
if [ -z "$tests" ]; then
echo "run all integration test cases ($coll_msg)"
else
echo "run integration test cases($coll_msg): $tests"
fi
$mysql_tester -port "$port" --collation-disable=$coll_disabled $tests
fi
}
function check_data_race() {
if [ "${TIDB_TEST_STORE_NAME}" = "tikv" ]; then
return
fi
race=`grep 'DATA RACE' $mysql_tester_log || true`
if [ ! -z "$race" ]; then
echo "tidb-server DATA RACE!"
cat $mysql_tester_log
exit 1
fi
}
enabled_new_collation=""
if [[ $collation_opt = 0 || $collation_opt = 2 ]]; then
enabled_new_collation=0
start_tidb_server
sleep 5
run_mysql_tester
kill -15 $SERVER_PID
while ps -p $SERVER_PID > /dev/null; do
sleep 1
done
check_data_race
fi
if [[ $collation_opt = 1 || $collation_opt = 2 ]]; then
enabled_new_collation=1
start_tidb_server
sleep 5
run_mysql_tester
kill -15 $SERVER_PID
while ps -p $SERVER_PID > /dev/null; do
sleep 1
done
check_data_race
fi
echo "integrationtest passed!"