README
¶
Preparations
-
The following executables must be copied or generated or linked into these locations.
bin/tidb-servercan be downloaded from tidb-master-linux-amd64 or installed by tiup, you can use the commandfind ~/.tiup -name tidb-serverto locatetidb-serverbinary file and copy itbin/sync_diff_inspector# generated bymake dm_integration_test_buildbin/miniocan be build from (https://github.com/minio/minio)bin/dm-master.test# generated bymake dm_integration_test_buildbin/dm-worker.test# generated bymake dm_integration_test_buildbin/dm-master.test.current# generated frombin/dm-master.testbymake compatibility_testbin/dm-worker.test.current# generated frombin/dm-worker.testbymake compatibility_testbin/dm-master.test.previous# generated frombin/dm-master.testbymake compatibility_testbin/dm-worker.test.previous# generated frombin/dm-worker.testbymake compatibility_test- gh-ost # must be added to path, or you can
export GHOST_BINARY=/path/to/gh-ost-binary - pt-online-schema-change # must be added to path, or you can
export PTOSC_BINARY=/path/to/pt-osc-binary - GNU sed # must be added to path, BSD sed user should be attention
- GNU awk # must be added to path
-
The following programs must be installed:
mysql(the CLI client, currently not supported for mysql client 8.0)python2.7orpython3.x
-
The user executing the tests must have permission to create the folder
/tmp/dm_test. All test artifacts will be written into this folder.
Running
Unit Test
- Run
make unit_testto run unit test
Integration Test
-
Run
make dm_integration_test_buildto generate DM related binary for integration test -
Setup two MySQL servers (the first one: 5.6 ~ 5.7; the second one: 8.0.21, suggest you are same as CI) with binlog enabled first and set
GTID_MODE=ON, You need set the mysql port and root password according to the following table.MySQL Host Port PASSWORD MySQL1 127.0.0.13306123456MySQL2 127.0.0.13307123456For the second MySQL server (with 8.0 version), you should setup it with
--default-authentication-plugin=mysql_native_password. -
Run
make integration_testto execute the integration tests. This command will- Check that all required executables exist.
- Execute
tests/run.sh
If want to run one integration test case only, just pass the CASE parameter, such as
make integration_test CASE=sharding.There exists some environment variables that you can set by yourself, including
RESET_MASTER,ONLINE_DDL_ENABLE. IfRESET_MASTERis not set or set to true,RESET MASTERwill be executed at upstream MySQL before each case.The online DDL test using pt-osc doesn't work if the upstream MySQL has different connect port and bind port (often caused by port forwarding via NAT). In this case, you must specify the real IP and port of MySQL. Otherwise you can skip online DDL test by
export ONLINE_DDL_ENABLE=false. -
After executing the tests, run
make coverageto get a coverage report at/tmp/dm_test/all_cov.html.
Compatibility Test
-
Run Compatibility test
Run
make compatibility_testwill run compatibility test. -
Setup two MySQL servers with binlog enabled first and set
GTID_MODE=ON, export proper environment variable. Variables and their default values are showed in following table.MySQL Host Port PASSWORD MySQL1 MYSQL_HOST1/127.0.0.1MYSQL_PORT1/3306MYSQL_PASSWORD1/123456MySQL2 MYSQL_HOST2/127.0.0.1MYSQL_PORT2/3307MYSQL_PASSWORD2/123456 -
Run other test with different version's dm-master and dm-worker
Run
make compatibility_test CASE={test_case}, for example,make compatibility_test CASE=http_apiswill run testhttp_apiswith previous dm-master and current dm-worker, and also current dm-master and previous dm-worker. Thetest_casecan beall, and will run all the test cases.
Writing new tests
- New integration tests can be written as shell scripts in
tests/TEST_NAME/run.sh. The script should exit with a nonzero error code on failure. - Add TEST_NAME to existing group in run_group.sh, or add a new group for it.
- If you add a new group, the name of the new group must be added to CI.
Note the integration test runs in parallel, and new added test case is not listed in CI, so remember to add the
TEST_NAMEof new added test case to fileothers_integration_2.txtin a newline.
Several convenient commands are provided:
run_dm_master <WORKDIR> <PORT> <CONFIG>— Startsdm-masterusing config provided, on given port, running in workdir.run_dm_worker <WORKDIR> <PORT> <CONFIG>— Startsdm-workerusing config provided, on given port, running in workdir.run_dm_ctl <WORKDIR> <MASTER_ADDR> <DMCTL_COMMAND>- Runsdmctlwith given command in non-interactive mode.run_sql <SQL> <PORT> <PASSWORD>— Executes an SQL query in database based on port providedrun_sql_file <path_to_SQL_file> <HOST> <PORT> <PASSWORD>— Executes all SQLs in given file to the database on port providedrun_sql_file_online_ddl <path_to_SQL_file> <HOST> <PORT> <PASSWORD> <DB> <ONLINE DDL TOOL>— Executes all SQLs in given file, will auto switch DDL to online DDL command.check_contains <TEXT>— Checks if the previousrun_sql/run_sql_fileresult contains the given text (in-Eformat)check_sync_diff <WORKDIR> <CONFIG>- Runssync_diff_inspectorto check diff between databases, using config file providedcheck_rpc_alive <CHECK_TOOL> <ADDR>- Wrapper to check a rpc address is available, at most 10 times.check_port_alive <PORT>- Wrapper to check a port is alive, at most 20 times.check_port <HOST> <PORT>- Checks a host:port is alive.wait_process_exit <process_name>- Wait for one or more processes to exit by given process name.check_metric <PORT> <METRIC_NAME> <RETRY_COUNT> <LOWER BOUND> <UPPER BOUND>- check metric value from prometheus.truncate_trace_events <PORT>- truncate trace server events records.