github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/http_api/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  MAX_RETRIES=50
    11  
    12  function run() {
    13  	# storage and kafka are the same as mysql
    14  	if [ "$SINK_TYPE" != "mysql" ]; then
    15  		return
    16  	fi
    17  
    18  	sudo python3 -m pip install -U requests==2.26.0
    19  
    20  	rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    21  
    22  	start_tidb_cluster --workdir $WORK_DIR --multiple-upstream-pd true
    23  
    24  	cd $WORK_DIR
    25  
    26  	run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --logsuffix 1
    27  	# wait for cdc run
    28  	ensure $MAX_RETRIES "$CDC_BINARY cli capture list 2>&1 | grep '\"is-owner\": true'"
    29  	owner_pid=$(ps -C $CDC_BINARY -o pid= | awk '{print $1}')
    30  	owner_id=$($CDC_BINARY cli capture list 2>&1 | awk -F '"' '/id/{print $4}')
    31  	echo "owner pid:" $owner_pid
    32  	echo "owner id" $owner_id
    33  
    34  	run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --addr "127.0.0.1:8301" --logsuffix 2
    35  	ensure $MAX_RETRIES "$CDC_BINARY cli capture list 2>&1 | grep -v \"$owner_id\" | grep id"
    36  	capture_id=$($CDC_BINARY cli capture list 2>&1 | awk -F '"' '/\"id/{print $4}' | grep -v "$owner_id")
    37  	echo "capture_id:" $capture_id
    38  
    39  	python3 $CUR/util/test_case.py check_health
    40  	python3 $CUR/util/test_case.py get_status
    41  
    42  	SINK_URI="mysql://normal:123456@127.0.0.1:3306/"
    43  	python3 $CUR/util/test_case.py create_changefeed "$SINK_URI"
    44  
    45  	run_sql "CREATE table test.simple(id int primary key, val int);"
    46  	run_sql "CREATE table test.\`simple-dash\`(id int primary key, val int);"
    47  	run_sql "CREATE table test.simple1(id int primary key, val int);"
    48  	run_sql "CREATE table test.simple2(id int primary key, val int);"
    49  	run_sql "INSERT INTO test.simple1(id, val) VALUES (1, 1);"
    50  	run_sql "INSERT INTO test.simple1(id, val) VALUES (2, 2);"
    51  	# wait for above sql done in the up source
    52  	sleep 2
    53  
    54  	check_table_exists test.simple1 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    55  
    56  	sequential_cases1=(
    57  		"list_changefeed"
    58  		"get_changefeed"
    59  		"pause_changefeed"
    60  		"update_changefeed"
    61  	)
    62  
    63  	for case in ${sequential_cases1[@]}; do
    64  		python3 $CUR/util/test_case.py "$case"
    65  	done
    66  
    67  	# kill the cdc owner server
    68  	kill_cdc_pid $owner_pid
    69  	# check that the new owner is elected
    70  	ensure $MAX_RETRIES "$CDC_BINARY cli capture list --server http://127.0.0.1:8301 2>&1 |grep $capture_id -A1 | grep '\"is-owner\": true'"
    71  	# restart the old owner capture
    72  	run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY
    73  	ensure $MAX_RETRIES "$CDC_BINARY cli capture list 2>&1 | grep '\"address\": \"127.0.0.1:8300\"'"
    74  
    75  	# make sure api works well after one owner was killed and another owner was elected
    76  	sequential_cases2=(
    77  		"list_changefeed"
    78  		"get_changefeed"
    79  		"pause_changefeed"
    80  		"resume_changefeed"
    81  		"rebalance_table"
    82  		"move_table"
    83  		"get_processor"
    84  		"list_processor"
    85  		"set_log_level"
    86  		"remove_changefeed"
    87  		"resign_owner"
    88  		# api v2
    89  		"get_tso"
    90  	)
    91  
    92  	for case in ${sequential_cases2[@]}; do
    93  		python3 $CUR/util/test_case.py "$case"
    94  	done
    95  	cleanup_process $CDC_BINARY
    96  }
    97  
    98  trap stop_tidb_cluster EXIT
    99  run $*
   100  check_logs $WORK_DIR
   101  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"