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