github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/http_proxies/run.sh (about) 1 #!/bin/bash 2 3 set -exu 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 TEST_HOST_LIST=(UP_TIDB_HOST UP_PD_HOST_{1..3} UP_TIKV_HOST_{1..3}) 12 # FIXME: hostname in macOS doesn't support -I option. 13 lan_addrs=($(hostname -I)) 14 lan_addr=${lan_addrs[0]-"127.0.0.1"} 15 export UP_TIDB_HOST=$lan_addr \ 16 UP_PD_HOST_1=$lan_addr \ 17 UP_PD_HOST_2=$lan_addr \ 18 UP_PD_HOST_3=$lan_addr \ 19 UP_TIKV_HOST_1=$lan_addr \ 20 UP_TIKV_HOST_2=$lan_addr \ 21 UP_TIKV_HOST_3=$lan_addr 22 23 proxy_pid="" 24 proxy_port=$(shuf -i 10081-20081 -n1) 25 function start_proxy() { 26 echo "dumpling grpc packet to $WORK_DIR/test_proxy.log..." 27 GO111MODULE=on WORK_DIR=$WORK_DIR go run $CUR/run-proxy.go --port=$proxy_port >$WORK_DIR/test_proxy.log & 28 proxy_pid=$! 29 echo "proxy port: $proxy_port" 30 echo "proxy pid: $proxy_pid" 31 } 32 33 function stop_proxy() { 34 kill "$proxy_pid" || true 35 } 36 37 function prepare() { 38 for host in "${TEST_HOST_LIST[@]}"; do 39 echo "$host $(printenv $host)" 40 case $(printenv $host) in 41 # Should we handle ::1/128 here? 42 127.*.*.*) 43 echo "[WARNING] http_proxies: the host of component $host is loopback, hence proxies would be ignored, skipping this test..." 44 exit 0 45 ;; 46 *) ;; 47 esac 48 done 49 50 rm -rf "$WORK_DIR" 51 mkdir -p "$WORK_DIR" 52 stop_tidb_cluster 53 start_tidb_cluster --workdir $WORK_DIR 54 55 start_proxy 56 # TODO: make sure the proxy is started. 57 sleep 5 58 export http_proxy=http://127.0.0.1:$proxy_port 59 export https_proxy=http://127.0.0.1:$proxy_port 60 echo "try to connect pd cluster via proxy, pd addr: $UP_PD_HOST_1:2379" 61 ensure 10 curl http://$UP_PD_HOST_1:2379/ 62 63 echo started proxy pid: $proxy_pid 64 echo started proxy at port: $proxy_port 65 66 cd $WORK_DIR 67 start_ts=$(run_cdc_cli_tso_query ${UP_PD_HOST_1} ${UP_PD_PORT_1}) 68 echo "query start ts: $start_ts" 69 70 run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY 71 echo started cdc server successfully 72 73 SINK_URI="blackhole:///" 74 run_cdc_cli changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI" 75 } 76 77 function check() { 78 services=($(cat $WORK_DIR/test_proxy.log | xargs -L1 dirname | sort | uniq)) 79 service_type_count=${#services[@]} 80 echo "captured services: " 81 echo ${services[@]} 82 # at least two types: 83 # "pdpb.PD" 84 # "tikvpb.TiKV" 85 if ! [ $service_type_count -ge 2 ]; then 86 echo "services didn't match expected." 87 echo "[total count]: $service_type_count (expected >= 2)" 88 exit 1 89 fi 90 } 91 92 trap "stop_tidb_cluster && stop_proxy" EXIT 93 94 if [ "$SINK_TYPE" == "mysql" ]; then 95 prepare 96 sleep 5 97 check 98 check_logs $WORK_DIR 99 fi 100 echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"