github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/run.sh (about) 1 #!/bin/bash 2 3 set -eu 4 5 TEST_DIR=/tmp/dm_test 6 export DM_MASTER_EXTRA_ARG="" 7 CUR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) 8 source $CUR/_utils/env_variables 9 10 stop_services() { 11 echo "..." 12 # clean sql mode 13 mysql -u root -h $MYSQL_HOST1 -P $MYSQL_PORT1 -p$MYSQL_PASSWORD1 -e "SET @@GLOBAL.SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'" 14 mysql -u root -h $MYSQL_HOST2 -P $MYSQL_PORT2 -p$MYSQL_PASSWORD2 -e "SET @@GLOBAL.SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'" 15 } 16 17 print_worker_stacks() { 18 if [ $? != 0 ]; then 19 mkdir -p "$TEST_DIR/goroutines/stack/log" 20 # don't know which case failed, so we print them all 21 for port in $MASTER_PORT1 $MASTER_PORT2 $MASTER_PORT3 $MASTER_PORT4 $MASTER_PORT5 $MASTER_PORT6; do 22 curl -sS "127.0.0.1:$port/debug/pprof/goroutine?debug=2" >"$TEST_DIR/goroutines/stack/log/master-$port.log" || true 23 done 24 for port in $WORKER1_PORT $WORKER2_PORT $WORKER3_PORT $WORKER4_PORT $WORKER5_PORT; do 25 curl -sS "127.0.0.1:$port/debug/pprof/goroutine?debug=2" >"$TEST_DIR/goroutines/stack/log/worker-$port.log" || true 26 done 27 fi 28 } 29 30 check_mysql() { 31 host=$1 32 port=$2 33 password=$3 34 while ! mysql -u root -h ${host} -P ${port} -p${password} -e 'select version();'; do 35 i=$((i + 1)) 36 if [ "$i" -gt 10 ]; then 37 echo "wait for mysql ${host}:${port} timeout" 38 exit 1 39 fi 40 sleep 1 41 done 42 } 43 44 set_default_variables() { 45 host=$1 46 port=$2 47 password=$3 48 mysql -u root -h ${host} -P ${port} -p${password} -e "set global character_set_server='utf8mb4';set global collation_server='utf8mb4_bin';" 49 } 50 51 start_services() { 52 stop_services 53 54 mkdir -p "$TEST_DIR" 55 rm -rf "$TEST_DIR/*.log" 56 57 $CUR/_utils/run_tidb_server $TIDB_PORT $TIDB_PASSWORD 58 59 i=0 60 61 check_mysql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 62 check_mysql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 63 set_default_variables $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 64 set_default_variables $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 65 } 66 67 if [ "$#" -ge 1 ]; then 68 test_case="$@" 69 else 70 test_case="*" 71 fi 72 73 should_run=0 74 if [ "$test_case" == "*" ]; then 75 should_run=1 76 elif [ "$test_case" == "compatibility" ]; then 77 should_run=1 78 else 79 exist_case="" 80 for one_case in $test_case; do 81 if [ ! -d "tests/$one_case" ]; then 82 echo $one_case "not exist" 83 else 84 exist_case="$exist_case $one_case" 85 should_run=1 86 fi 87 done 88 test_case=$exist_case 89 fi 90 91 if [ $should_run -eq 0 ]; then 92 exit 0 93 fi 94 95 trap stop_services EXIT 96 trap print_worker_stacks EXIT 97 start_services 98 99 function run() { 100 script=$1 101 echo "Running test $script..." 102 # run in verbose mode? 103 echo "Verbose mode = $VERBOSE" 104 if $VERBOSE; then 105 TEST_DIR="$TEST_DIR" \ 106 PATH="tests/_utils:$PATH" \ 107 TEST_NAME="$(basename "$(dirname "$script")")" \ 108 bash -x "$script" 109 else 110 TEST_DIR="$TEST_DIR" \ 111 PATH="tests/_utils:$PATH" \ 112 TEST_NAME="$(basename "$(dirname "$script")")" \ 113 bash +x "$script" 114 fi 115 } 116 117 if [ "$test_case" == "*" ]; then 118 for script in $CUR/$test_case/run.sh; do 119 echo "start running case: [$test_case] script: [$script]" 120 run $script 121 done 122 elif [ "$test_case" == "compatibility" ]; then 123 script="$CUR/compatibility/start.sh" 124 echo "start running case: [$test_case] script: [$script]" 125 run $script 126 else 127 for name in $test_case; do 128 script="$CUR/$name/run.sh" 129 echo "start running case: [$name] script: [$script]" 130 run $script 131 done 132 fi