github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/_utils/wait_until_sync (about)

     1  #!/bin/bash
     2  # tools to query-status until Sync, will print unit and progress. This only works for single worker case
     3  # parameter 1: work directory
     4  # parameter 2: master-addr port
     5  
     6  workdir=$1
     7  master_addr=$2
     8  cmd="query-status test"
     9  
    10  PWD=$(pwd)
    11  binary=$PWD/bin/dmctl.test
    12  ts=$(date +"%s")
    13  dmctl_log=$workdir/dmctl.$ts.log
    14  pid=$$
    15  
    16  while true; do
    17  	sleep 5
    18  	echo "$cmd" | $binary -test.coverprofile="$TEST_DIR/cov.$TEST_NAME.dmctl.$ts.$pid.out" DEVEL --master-addr=$master_addr >$dmctl_log 2>&1
    19  
    20  	value="\"stage\": \"Paused\""
    21  	# below grep will print the count of $value, exit when not 0
    22  	sed "s/$value/$value\n/g" $dmctl_log | grep -c "$value" && exit 1 || true
    23  
    24  	value="\"unit\": \"Dump\""
    25  	got=$(sed "s/$value/$value\n/g" $dmctl_log | grep -c "$value")
    26  	if [ "$got" -eq 1 ]; then
    27  		echo "in Dump unit"
    28  		continue
    29  	fi
    30  
    31  	value="\"unit\": \"Load\""
    32  	got=$(sed "s/$value/$value\n/g" $dmctl_log | grep -c "$value")
    33  	if [ "$got" -eq 1 ]; then
    34  		echo -n "in Load unit"
    35  		grep "progress" $dmctl_log
    36  		continue
    37  	fi
    38  
    39  	value="\"unit\": \"Sync\""
    40  	got=$(sed "s/$value/$value\n/g" $dmctl_log | grep -c "$value")
    41  	if [ "$got" -eq 1 ]; then
    42  		echo "in Sync unit"
    43  		exit 0
    44  	fi
    45  
    46  	exit 1
    47  done
    48  
    49  # gocovmerge doesn't support merge profiles with different modes, however atomic
    50  # mode and count mode have the same profile format, so we need to unify cover
    51  # mode before running gocovmerge. As coverage file is not generated synchronously,
    52  # we will patch covermode before `make coverage`