Skip to content

Commit cd65f2e

Browse files
committed
introduce integrationtest2
1 parent b334ea5 commit cd65f2e

File tree

9 files changed

+674
-186
lines changed

9 files changed

+674
-186
lines changed

tests/integrationtest/run-tests.sh

Lines changed: 19 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,12 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
set -x
17-
1816
TIDB_TEST_STORE_NAME=$TIDB_TEST_STORE_NAME
1917
TIKV_PATH=$TIKV_PATH
20-
START_TIDB_CLUSTER=$START_TIDB_CLUSTER
21-
22-
# Variables to set paths for each server binary
23-
TIDB_BIN="./third_bin/tidb-server"
24-
TIKV_BIN="./third_bin/tikv-server"
25-
PD_BIN="./third_bin/pd-server"
26-
DUMPLING_BIN="./third_bin/dumpling"
27-
TICDC_BIN="./third_bin/cdc"
28-
TIFLASH_BIN="./third_bin/tiflash-server"
29-
30-
# Variables to set data directories
31-
PD_DATA_DIR="./data/pd_data"
32-
PD_DATA_DIR2="./data/pd_data2"
33-
TIKV_DATA_DIR="./data/tikv_data"
34-
TIKV_DATA_DIR2="./data/tikv_data2"
35-
TIFLASH_DATA_DIR="./data/tiflash_data"
36-
TIFLASH_DATA_DIR2="./data/tiflash_data2"
37-
TICDC_DATA_DIR="./data/ticdc_data"
38-
39-
rm -rf ./data
40-
mkdir ./data
41-
42-
TIDB_LOG_FILE="./logs/tidb.log"
43-
TIDB_LOG_FILE2="./logs/tidb2.log"
44-
TIKV_LOG_FILE="./logs/tikv.log"
45-
TIKV_LOG_FILE2="./logs/tikv2.log"
46-
TIFLASH_LOG_FILE="./logs/tiflash.log"
47-
TIFLASH_LOG_FILE2="./logs/tiflash2.log"
48-
PD_LOG_FILE="./logs/pd.log"
49-
PD_LOG_FILE2="./logs/pd2.log"
50-
TICDC_LOG_FILE="./logs/ticdc.log"
51-
52-
rm -rf ./logs
53-
mkdir ./logs
5418

5519
build=1
5620
mysql_tester="./mysql_tester"
5721
tidb_server=""
58-
ticdc_server=$TICDC_BIN
5922
portgenerator=""
6023
mysql_tester_log="./integration-test.out"
6124
tests=""
@@ -249,155 +212,22 @@ rm -rf $mysql_tester_log
249212
ports=($(find_multiple_available_ports 4000 2))
250213
port=${ports[0]}
251214
status=${ports[1]}
252-
# PD Server Configuration
253-
start_pd_server() {
254-
client_port=${1:-2379}
255-
peer_port=${2:-2380}
256-
data_dir=${3:-$PD_DATA_DIR}
257-
log_dir=${4:-$PD_LOG_FILE}
258-
259-
echo "Starting PD server..."
260-
mkdir -p $data_dir
261-
262-
$PD_BIN --name="pd" --data-dir="$data_dir" --log-file="$log_dir" \
263-
--client-urls="http://127.0.0.1:$client_port" \
264-
--peer-urls="http://127.0.0.1:$peer_port" \
265-
--advertise-client-urls="http://127.0.0.1:$client_port" \
266-
--advertise-peer-urls="http://127.0.0.1:$peer_port" &
267-
# --config="config/pd.toml"
268-
sleep 5 # Wait for PD to sart
269-
}
270-
271-
# TiKV Server Configuration
272-
start_tikv_server() {
273-
pd_client_port=${1:-2379}
274-
tikv_port=${2:-20160}
275-
tikv_status_port=${3:-20180}
276-
data_dir=${4:-$TIKV_DATA_DIR}
277-
log_dir=${5:-$TIKV_LOG_FILE}
278-
279-
echo "Starting TiKV server..."
280-
mkdir -p $data_dir
281-
282-
$TIKV_BIN --pd="http://127.0.0.1:$pd_client_port" \
283-
--addr="127.0.0.1:$tikv_port" \
284-
--advertise-addr="127.0.0.1:$tikv_port" \
285-
--status-addr="127.0.0.1:$tikv_status_port" \
286-
--data-dir="$data_dir" \
287-
--log-file="$log_dir" &
288-
sleep 5 # Wait for TiKV to connect to PD
289-
}
290-
291-
# TiFlash Server Configuration
292-
start_tiflash_server() {
293-
echo "Starting TiFlash server..."
294-
mkdir -p $TIFLASH_DATA_DIR
295-
$TIFLASH_BIN --data-dir=$TIFLASH_DATA_DIR --log-file=tiflash.log &
296-
297-
sleep 5 # Wait for TiFlash to connect
298-
}
299215

300216
function start_tidb_server()
301217
{
302-
pd_client_addr=${1:-127.0.0.1:2379}
303-
tidb_port=${2:-4000}
304-
tidb_status_port=${3:-10080}
305-
log_file=${4:-$TIDB_LOG_FILE}
306-
307218
config_file="config.toml"
308219
if [[ $enabled_new_collation = 0 ]]; then
309220
config_file="disable_new_collation.toml"
310221
fi
311-
echo "start tidb-server, log file: $log_file"
222+
echo "start tidb-server, log file: $mysql_tester_log"
312223
if [ "${TIDB_TEST_STORE_NAME}" = "tikv" ]; then
313-
$tidb_server -P "$tidb_port" \
314-
-status "$tidb_status_port" \
315-
-config $config_file \
316-
-store tikv \
317-
-path "${pd_client_addr}" > $log_file 2>&1 &
224+
$tidb_server -P "$port" -status "$status" -config $config_file -store tikv -path "${TIKV_PATH}" > $mysql_tester_log 2>&1 &
318225
SERVER_PID=$!
319226
else
320-
$tidb_server -P "$tidb_port" \
321-
-status "$tidb_status_port" \
322-
-config $config_file \
323-
-store unistore \
324-
-path "" > $log_file 2>&1 &
227+
$tidb_server -P "$port" -status "$status" -config $config_file -store unistore -path "" > $mysql_tester_log 2>&1 &
325228
SERVER_PID=$!
326229
fi
327-
echo "tidb-server(PID: $SERVER_PID) started, port: $tidb_port"
328-
}
329-
330-
function start_ticdc_server() {
331-
pd_client_addr=${1:-http://127.0.0.1:2379}
332-
ticdc_port=${2:-8300}
333-
downstream_port=${3:-4100}
334-
335-
echo "Starting TiCDC server..."
336-
mkdir -p $TICDC_DATA_DIR
337-
$TICDC_BIN server --pd=$pd_client_addr --addr=127.0.0.1:$ticdc_port --data-dir=$TICDC_DATA_DIR --log-file=$TICDC_LOG_FILE &
338-
sleep 5 # Wait for TiCDC to connect
339-
340-
$TICDC_BIN cli changefeed create --server=127.0.0.1:$ticdc_port --sink-uri="mysql://root:@127.0.0.1:$downstream_port/" --changefeed-id="simple-replication-task"
341-
sleep 5 # Wait for changefeed to connect
342-
}
343-
344-
function start_tidb_cluster()
345-
{
346-
local ports=($(find_multiple_available_ports 2379 2))
347-
if [ $? -ne 0 ]; then
348-
echo "Error: Could not find multiple available ports." >&2
349-
exit 1
350-
fi
351-
pd_client_port=${ports[0]}
352-
pd_peer_port=${ports[1]}
353-
upstream_pd_client_port=$pd_client_port
354-
start_pd_server $pd_client_port $pd_peer_port $PD_DATA_DIR $PD_LOG_FILE
355-
356-
local ports=($(find_multiple_available_ports 20160 2))
357-
if [ $? -ne 0 ]; then
358-
echo "Error: Could not find multiple available ports." >&2
359-
exit 1
360-
fi
361-
tikv_port=${ports[0]}
362-
tikv_status_port=${ports[1]}
363-
start_tikv_server $pd_client_port $tikv_port $tikv_status_port $TIKV_DATA_DIR $TIKV_LOG_FILE
364-
365-
tidb_port=$(find_available_port 4000)
366-
# Tricky: update `port` here.
367-
port=$tidb_port
368-
tidb_status_port=$(find_available_port 10080)
369-
start_tidb_server "127.0.0.1:$pd_client_port" $tidb_port $tidb_status_port $TIDB_LOG_FILE
370-
371-
local ports=($(find_multiple_available_ports 2379 2))
372-
if [ $? -ne 0 ]; then
373-
echo "Error: Could not find multiple available ports." >&2
374-
exit 1
375-
fi
376-
pd_client_port=${ports[0]}
377-
pd_peer_port=${ports[1]}
378-
start_pd_server $pd_client_port $pd_peer_port $PD_DATA_DIR2 $PD_LOG_FILE2
379-
380-
local ports=($(find_multiple_available_ports 20160 2))
381-
if [ $? -ne 0 ]; then
382-
echo "Error: Could not find multiple available ports." >&2
383-
exit 1
384-
fi
385-
tikv_port=${ports[0]}
386-
tikv_status_port=${ports[1]}
387-
start_tikv_server $pd_client_port $tikv_port $tikv_status_port $TIKV_DATA_DIR2 $TIKV_LOG_FILE2
388-
389-
tidb_port=$(find_available_port 4000)
390-
tidb_status_port=$(find_available_port 10080)
391-
start_tidb_server "127.0.0.1:$pd_client_port" $tidb_port $tidb_status_port $TIDB_LOG_FILE2
392-
393-
echo "TiDB cluster started successfully!"
394-
read -p "Press [Enter] key to go on..."
395-
396-
ticdc_port=$(find_available_port 8300)
397-
start_ticdc_server "http://127.0.0.1:$upstream_pd_client_port" $ticdc_port $tidb_port
398-
399-
echo "TiCDC started successfully!"
400-
read -p "Press [Enter] key to go on..."
230+
echo "tidb-server(PID: $SERVER_PID) started"
401231
}
402232

403233
function run_mysql_tester()
@@ -474,21 +304,24 @@ function check_case_name() {
474304
check_case_name
475305
if [[ $collation_opt = 0 || $collation_opt = 2 ]]; then
476306
enabled_new_collation=0
477-
else
478-
enabled_new_collation=1
307+
start_tidb_server
308+
run_mysql_tester
309+
kill -15 $SERVER_PID
310+
while ps -p $SERVER_PID > /dev/null; do
311+
sleep 1
312+
done
313+
check_data_race
479314
fi
480315

481-
if [ -z "$START_TIDB_CLUSTER" ]; then
316+
if [[ $collation_opt = 1 || $collation_opt = 2 ]]; then
317+
enabled_new_collation=1
482318
start_tidb_server
483-
else
484-
start_tidb_cluster
319+
run_mysql_tester
320+
kill -15 $SERVER_PID
321+
while ps -p $SERVER_PID > /dev/null; do
322+
sleep 1
323+
done
324+
check_data_race
485325
fi
486326

487-
run_mysql_tester
488-
kill -15 $SERVER_PID
489-
while ps -p $SERVER_PID > /dev/null; do
490-
sleep 1
491-
done
492-
check_data_race
493-
494327
echo "integrationtest passed!"

tests/integrationtest2/README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# IntegrationTest
2+
3+
IntegrationTest is a integration test command tool, also with some useful test cases for TiDB execute plan logic, we can run case via `run-tests.sh`.
4+
5+
```
6+
Usage: ./run-tests.sh [options]
7+
8+
-h: Print this help message.
9+
10+
-s <tidb-server-path>: Use tidb-server in <tidb-server-path> for testing.
11+
eg. "./run-tests.sh -s ./integrationtest_tidb-server"
12+
13+
-b <y|Y|n|N>: "y" or "Y" for building test binaries [default "y" if this option is not specified].
14+
"n" or "N" for not to build.
15+
The building of tidb-server will be skiped if "-s <tidb-server-path>" is provided.
16+
17+
-r <test-name>|all: Run tests in file "t/<test-name>.test" and record result to file "r/<test-name>.result".
18+
"all" for running all tests and record their results.
19+
20+
-t <test-name>: Run tests in file "t/<test-name>.test".
21+
This option will be ignored if "-r <test-name>" is provided.
22+
Run all tests if this option is not provided.
23+
24+
-v <vendor-path>: Add <vendor-path> to $GOPATH.
25+
26+
-p <portgenerator-path>: Use port generator in <portgenerator-path> for generating port numbers.
27+
```
28+
29+
## How it works
30+
31+
IntegrationTest will read test case in `t/*.test`, and execute them in TiDB server with `s/*.json` stat, and compare integration result in `r/*.result`.
32+
33+
For convenience, we can generate new `*.result` and `*.json` from execute by use `-r` parameter for `run-tests.sh`
34+
35+
## Usage
36+
37+
### Regression Execute Plan Modification
38+
39+
After modify code and before commit, please run this command under TiDB root folder.
40+
41+
```sh
42+
make dev
43+
```
44+
45+
or
46+
47+
```sh
48+
make integrationtest
49+
```
50+
51+
It will identify execute plan change.
52+
53+
### Generate New Result from Execute
54+
55+
Add a new test file in `t/` folder, file name should ended with `.test`. Or add new test queries at the end of some files. Then run shell below, it will generate results based on last execution.
56+
57+
```sh
58+
cd tests/integrationtest
59+
./run-tests.sh -r [casename]
60+
```
61+
62+
## How to debug integration test
63+
64+
### Visual Studio Code
65+
66+
1. Add or create a configuration to `.vscode/launch.json`, an example is shown below. If you want to change some configurations, such as using `TiKV` to run integration tests or others, you can modify `pkg/config/config.toml.example`.
67+
68+
```json
69+
{
70+
"version": "0.2.0",
71+
"configurations": [
72+
{
73+
"name": "Debug TiDB With Default Config",
74+
"type": "go",
75+
"request": "launch",
76+
"mode": "auto",
77+
"program": "${fileWorkspaceFolder}/cmd/tidb-server",
78+
"args": ["--config=${fileWorkspaceFolder}/pkg/config/config.toml.example"]
79+
}
80+
]
81+
}
82+
```
83+
84+
2. To run `TiDB-Server`, you could bring up **Run and Debug** view, select the **Run and Debug** icon in the **Activity Bar** on the side of VS Code. You can also use shortcut **F5**.
85+
86+
3. Use any mysql client application you like to run SQLs in integration test, the default port is `4000` and default user is `root` without password. Taking `mysql` as an example, you can use `mysql --comments --host 127.0.0.1 --port 4000 -u root` command to do this.
87+
88+
### Goland
89+
90+
You could follow <https://pingcap.github.io/tidb-dev-guide/get-started/setup-an-ide.html#run-or-debug> to run a `TiDB-Server` with or without `TiKV`. Then use any mysql client application you like to run SQLs.

tests/integrationtest2/config.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2021 PingCAP, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
lease = "0"
16+
host = "127.0.0.1"
17+
new_collations_enabled_on_first_bootstrap = true
18+
enable-table-lock = true
19+
20+
[status]
21+
status-host = "127.0.0.1"
22+
23+
[performance]
24+
stats-lease = "0"
25+
26+
[tikv-client.async-commit]
27+
safe-window = 0
28+
allowed-clock-drift = 0
29+
30+
[experimental]
31+
enable-new-charset = true
32+
allow-expression-index = true

0 commit comments

Comments
 (0)