github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/sink_hang/run.sh (about) 1 #!/bin/bash 2 3 set -e 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 CDC_COUNT=3 12 DB_COUNT=4 13 MAX_RETRIES=20 14 15 function check_changefeed_state() { 16 pd_addr=$1 17 changefeed_id=$2 18 expected=$3 19 state=$(cdc cli --pd=$pd_addr changefeed query -s -c $changefeed_id|jq -r ".state") 20 if [[ "$state" != "$expected" ]];then 21 echo "unexpected state $state, expected $expected" 22 exit 1 23 fi 24 } 25 26 export -f check_changefeed_state 27 28 function run() { 29 # kafka is not supported yet. 30 if [ "$SINK_TYPE" == "kafka" ]; then 31 return 32 fi 33 34 rm -rf $WORK_DIR && mkdir -p $WORK_DIR 35 start_tidb_cluster --workdir $WORK_DIR 36 cd $WORK_DIR 37 38 pd_addr="http://$UP_PD_HOST_1:$UP_PD_PORT_1" 39 TOPIC_NAME="ticdc-sink-hang-test-$RANDOM" 40 case $SINK_TYPE in 41 kafka) SINK_URI="kafka://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&kafka-version=${KAFKA_VERSION}";; 42 *) SINK_URI="mysql://normal:123456@127.0.0.1:3306/?max-txn-row=1";; 43 esac 44 if [ "$SINK_TYPE" == "kafka" ]; then 45 run_kafka_consumer $WORK_DIR "kafka://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&version=${KAFKA_VERSION}" 46 fi 47 48 export GO_FAILPOINTS='github.com/pingcap/ticdc/cdc/sink/MySQLSinkHangLongTime=1*return(true);github.com/pingcap/ticdc/cdc/sink/MySQLSinkExecDMLError=1*return(true)' 49 run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --addr "127.0.0.1:8300" --pd $pd_addr 50 changefeed_id=$(cdc cli changefeed create --pd=$pd_addr --sink-uri="$SINK_URI" 2>&1|tail -n2|head -n1|awk '{print $2}') 51 52 run_sql "CREATE DATABASE sink_hang;" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 53 run_sql "CREATE table sink_hang.t1(id int primary key auto_increment, val int);" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 54 run_sql "CREATE table sink_hang.t2(id int primary key auto_increment, val int);" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 55 run_sql "BEGIN; INSERT INTO sink_hang.t1 VALUES (),(),(); INSERT INTO sink_hang.t2 VALUES (),(),(); COMMIT" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 56 57 ensure $MAX_RETRIES check_changefeed_state $pd_addr $changefeed_id "stopped" 58 cdc cli changefeed resume --changefeed-id=$changefeed_id --pd=$pd_addr 59 ensure $MAX_RETRIES check_changefeed_state $pd_addr $changefeed_id "normal" 60 61 check_table_exists "sink_hang.t1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 62 check_table_exists "sink_hang.t2" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 63 check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml 64 65 cleanup_process $CDC_BINARY 66 } 67 68 trap stop_tidb_cluster EXIT 69 run $* 70 check_logs $WORK_DIR 71 echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"