github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/fake_rotate_event/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=$TEST_DIR/$TEST_NAME
     8  db="fake_rotate_event"
     9  tb="t1"
    10  
    11  function run() {
    12  	run_sql_file $cur/data/db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    13  
    14  	# start DM worker and master
    15  	run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml
    16  	check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT
    17  	run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml
    18  	check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT
    19  
    20  	# operate mysql config to worker
    21  	cp $cur/conf/source1.yaml $WORK_DIR/source1.yaml
    22  	dmctl_operate_source create $WORK_DIR/source1.yaml $SOURCE_ID1
    23  	dmctl_start_task_standalone "$cur/conf/dm-task.yaml" "--remove-meta"
    24  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    25  		"query-status test" \
    26  		"\"result\": true" 2 \
    27  		'"synced": true' 1
    28  
    29  	# make binlog rotate
    30  	run_sql_source1 "flush logs;"
    31  	run_sql_source1 "use $db; insert into $tb values (3, 3, 3)"
    32  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
    33  
    34  	echo "kill dm-worker"
    35  	kill_process dm-worker1
    36  	check_port_offline $WORKER1_PORT 20
    37  
    38  	# make fake rotate event and rewrite binlog filename to mysql-bin.000001
    39  	export GO_FAILPOINTS='github.com/pingcap/tiflow/dm/syncer/binlogstream/MakeFakeRotateEvent=return("mysql-bin.000001")'
    40  	run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml
    41  	check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT
    42  
    43  	# make a fake rotate event
    44  	run_sql_source1 "flush logs;"
    45  	run_sql_source1 "use $db;alter table $tb add column info2 varchar(40);" # trigger a flush job
    46  	run_sql_source1 "use $db; insert into $tb values (4, 4, 4,'info')"
    47  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
    48  
    49  	# check syncer's binlog filename same with fake rotate file name
    50  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    51  		"query-status test" \
    52  		"\"result\": true" 2 \
    53  		"mysql-bin.000001" 1
    54  
    55  	export GO_FAILPOINTS=''
    56  }
    57  
    58  cleanup_data fake_rotate_event
    59  # also cleanup dm processes in case of last run failed
    60  cleanup_process $*
    61  run $*
    62  cleanup_process $*
    63  
    64  echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"