github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/server_config_compatibility/run.sh (about) 1 #!/bin/bash 2 3 set -eu 4 5 CUR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) 6 source $CUR/../_utils/test_prepare 7 WORK_DIR=$OUT_DIR/$TEST_NAME 8 CDC_BINARY=cdc.test 9 SINK_TYPE=$1 10 11 function prepare() { 12 rm -rf $WORK_DIR && mkdir -p $WORK_DIR 13 14 start_tidb_cluster --workdir $WORK_DIR 15 16 cd $WORK_DIR 17 18 # record tso before we create tables to skip the system table DDLs 19 start_ts=$(run_cdc_cli_tso_query ${UP_PD_HOST_1} ${UP_PD_PORT_1}) 20 21 run_sql "CREATE table test.simple1(id int primary key, val int);" 22 run_sql "CREATE table test.simple2(id int primary key, val int);" 23 24 run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --config $CUR/conf/server.toml 25 26 SINK_URI="mysql+ssl://normal:123456@127.0.0.1:3306/" 27 run_cdc_cli changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI" 28 } 29 30 function sql_check() { 31 # run check in sequence and short circuit principle, if error hanppens, 32 # the following statement will be not executed 33 34 # check table simple1. 35 run_sql "SELECT id, val FROM test.simple1;" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} && 36 check_contains "id: 1" && 37 check_contains "val: 1" && 38 check_contains "id: 2" && 39 check_contains "val: 22" && 40 check_not_contains "id: 3" && 41 42 # check table simple2. 43 run_sql "SELECT id, val FROM test.simple2;" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} && 44 check_contains "id: 1" && 45 check_contains "val: 1" && 46 check_contains "id: 2" && 47 check_contains "val: 22" && 48 check_not_contains "id: 3" 49 } 50 51 function sql_test() { 52 # test insert/update/delete for two table in the same way. 53 run_sql "INSERT INTO test.simple1(id, val) VALUES (1, 1);" 54 run_sql "INSERT INTO test.simple1(id, val) VALUES (2, 2);" 55 run_sql "INSERT INTO test.simple1(id, val) VALUES (3, 3);" 56 57 # update id = 2 and delete id = 3 58 run_sql "UPDATE test.simple1 set val = 22 where id = 2;" 59 run_sql "DELETE from test.simple1 where id = 3;" 60 61 # same dml for table simple2 62 run_sql "INSERT INTO test.simple2(id, val) VALUES (1, 1);" 63 run_sql "INSERT INTO test.simple2(id, val) VALUES (2, 2);" 64 run_sql "INSERT INTO test.simple2(id, val) VALUES (3, 3);" 65 66 run_sql "UPDATE test.simple2 set val = 22 where id = 2;" 67 run_sql "DELETE from test.simple2 where id = 3;" 68 69 i=0 70 check_time=50 71 set +e 72 while [ $i -lt $check_time ]; do 73 sql_check 74 ret=$? 75 if [ "$ret" == 0 ]; then 76 echo "check data successfully" 77 break 78 fi 79 ((i++)) 80 echo "check data failed $i-th time, retry later" 81 sleep 2 82 done 83 set -e 84 85 if [ $i -ge $check_time ]; then 86 echo "check data failed at last" 87 exit 1 88 fi 89 90 cleanup_process $CDC_BINARY 91 } 92 93 trap stop_tidb_cluster EXIT 94 # No need to test different sink type. 95 # Because we only test the compatibility of the server config file. 96 if [ "$SINK_TYPE" == "mysql" ]; then 97 prepare $* 98 sql_test $* 99 check_logs $WORK_DIR 100 fi 101 echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"