diff --git a/dm/tests/_utils/run_downstream_cluster b/dm/tests/_utils/run_downstream_cluster index 36038c74e07..0d755cbd8d2 100755 --- a/dm/tests/_utils/run_downstream_cluster +++ b/dm/tests/_utils/run_downstream_cluster @@ -1,7 +1,7 @@ -#!/bin/bash +#!/usr/bin/env bash # tools to run a TiDB cluster # parameter 1: work directory -set -eu +set -eux WORK_DIR=$1 export PD_PEER_ADDR="127.0.0.1:2380" @@ -24,7 +24,7 @@ start_pd() { max-replicas = 1 EOF - pd-server --version + bin/pd-server --version mkdir -p "$WORK_DIR/pd" bin/pd-server \ --client-urls "http://$PD_ADDR" \ @@ -32,14 +32,21 @@ EOF --log-file "$WORK_DIR/pd.log" \ --config "$WORK_DIR/pd.toml" \ --data-dir "$WORK_DIR/pd" & - # wait until PD is online... + sleep 5 i=0 - while ! curl "http://$PD_ADDR/pd/api/v1/version"; do + while true; do + response=$(curl -s -o /dev/null -w "%{http_code}" "http://$PD_ADDR/pd/api/v1/version" || echo "") + echo "curl response: $response" + if [ "$response" -eq 200 ]; then + echo 'Start PD success' + break + fi i=$((i + 1)) if [ "$i" -gt 20 ]; then echo 'Failed to start PD' return 1 fi + echo 'Waiting for PD ready...' sleep 3 done } @@ -47,6 +54,7 @@ EOF start_tikv() { echo "Starting TiKV..." mkdir -p "$WORK_DIR/tikv" + bin/tikv-server --version bin/tikv-server \ --pd "$PD_ADDR" \ -A "$TIKV_ADDR" \ @@ -54,18 +62,35 @@ start_tikv() { --log-file "$WORK_DIR/tikv.log" \ --log-level info \ -s "$WORK_DIR/tikv" & - while ! curl "http://$PD_ADDR/pd/api/v1/cluster/status" | tee /dev/stderr | grep '"is_initialized": true'; do + sleep 5 + i=0 + while true; do + response=$(curl -s "http://$PD_ADDR/pd/api/v1/cluster/status" || echo "") + + if [ -z "$response" ]; then + echo "Failed to connect to PD server" + else + echo "PD response: $response" + if echo "$response" | grep -q '"is_initialized": true'; then + echo "TiKV cluster initialized successfully" + break + fi + fi + i=$((i + 1)) if [ "$i" -gt 20 ]; then - echo 'Failed to initialize TiKV cluster' + echo 'Failed to initialize TiKV cluster after 20 attempts' return 1 fi + + echo 'Waiting for TiKV ready...' sleep 5 done } start_tidb() { echo "Starting TiDB..." + bin/tidb-server -V bin/tidb-server \ -P 4000 \ --status 10080 \ @@ -73,14 +98,22 @@ start_tidb() { --store tikv \ --path "$PD_ADDR" \ --log-file "$WORK_DIR/tidb.log" & - + sleep 5 + # wait until TiDB is online... i=0 - while ! curl "http://$TIDB_IP:10080/status"; do + while true; do + response=$(curl -s -o /dev/null -w "%{http_code}" "http://$TIDB_IP:10080/status" || echo "") + echo "curl response: $response" + if [ "$response" -eq 200 ]; then + echo 'Start TiDB success' + break + fi i=$((i + 1)) if [ "$i" -gt 50 ]; then echo 'Failed to start TiDB' return 1 fi + echo 'Waiting for TiDB ready...' sleep 3 done } diff --git a/dm/tests/_utils/run_sql b/dm/tests/_utils/run_sql index 555fc4a2337..66d91a40a28 100755 --- a/dm/tests/_utils/run_sql +++ b/dm/tests/_utils/run_sql @@ -18,5 +18,5 @@ fi if [[ $# -ge 4 ]]; then echo "$1" | iconv -f utf8 -t $4 | mysql -u$user -h127.0.0.1 -P$2 -p$3 --default-character-set $4 -E >>$OUTFILE else - mysql -u$user -h127.0.0.1 -P$2 -p$3 --default-character-set utf8 -E -e "$1" >>$OUTFILE + MYSQL_PWD=$3 mysql -u$user -h127.0.0.1 -P$2 --default-character-set utf8 -E -e "$1" >>$OUTFILE fi diff --git a/dm/tests/many_tables/run.sh b/dm/tests/many_tables/run.sh index 3fc99f2c4bb..0ffb9a6a680 100644 --- a/dm/tests/many_tables/run.sh +++ b/dm/tests/many_tables/run.sh @@ -151,7 +151,9 @@ function run() { pkill -hup tidb-server 2>/dev/null || true wait_process_exit tidb-server # now worker will process some binlog events, save table checkpoint and meet downstream error + echo "start incremental_data_2" incremental_data_2 + echo "finish incremental_data_2" sleep 30 resume_num=$(grep 'unit process error' $WORK_DIR/worker1/log/dm-worker.log | wc -l) diff --git a/dm/tests/requirements.txt b/dm/tests/requirements.txt index f2293605cf1..8ca17f61940 100644 --- a/dm/tests/requirements.txt +++ b/dm/tests/requirements.txt @@ -1 +1,2 @@ requests +ipaddress diff --git a/dm/tests/tls/run.sh b/dm/tests/tls/run.sh index 3fc76387f38..b5046829b78 100644 --- a/dm/tests/tls/run.sh +++ b/dm/tests/tls/run.sh @@ -42,8 +42,13 @@ EOF --log-file "$WORK_DIR/tidb.log" 2>&1 & sleep 5 + + echo "show databases without TLS" + mysql -uroot -h127.0.0.1 -P4400 --default-character-set utf8 -E -e "SHOW DATABASES;" + echo "drop database tls with TLS" # if execute failed, print tidb's log for debug mysql -uroot -h127.0.0.1 -P4400 --default-character-set utf8 --ssl-ca $cur/conf/ca.pem --ssl-cert $cur/conf/dm.pem --ssl-key $cur/conf/dm.key -E -e "drop database if exists tls" || (cat $WORK_DIR/tidb.log && exit 1) + echo "drop database dm_meta with TLS" mysql -uroot -h127.0.0.1 -P4400 --default-character-set utf8 --ssl-ca $cur/conf/ca.pem --ssl-cert $cur/conf/dm.pem --ssl-key $cur/conf/dm.key -E -e "drop database if exists dm_meta" }