From 2d7accfaa6101d307de94489532993bbcc97666f Mon Sep 17 00:00:00 2001 From: lance6716 Date: Mon, 24 Aug 2020 16:53:10 +0800 Subject: [PATCH] test: remove wait time to reduce indetermination --- syncer/streamer_controller.go | 26 +++++++------------------- tests/drop_column_with_index/run.sh | 5 ++--- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/syncer/streamer_controller.go b/syncer/streamer_controller.go index 94449faceb..dd4d58e90a 100644 --- a/syncer/streamer_controller.go +++ b/syncer/streamer_controller.go @@ -15,7 +15,6 @@ package syncer import ( "context" - "fmt" "strings" "sync" "time" @@ -212,6 +211,8 @@ func (c *StreamerController) RedirectStreamer(tctx *tcontext.Context, location b return c.resetReplicationSyncer(tctx, location) } +var mockRestarted = false + // GetEvent returns binlog event, should only have one thread call this function. func (c *StreamerController) GetEvent(tctx *tcontext.Context) (event *replication.BinlogEvent, err error) { ctx, cancel := context.WithTimeout(tctx.Context(), common.SlaveReadTimeout) @@ -223,24 +224,11 @@ func (c *StreamerController) GetEvent(tctx *tcontext.Context) (event *replicatio } }) - failpoint.Inject("SyncerGetEventError", func(val failpoint.Value) { - str, ok := val.(string) - if !ok { - tctx.L().Warn(fmt.Sprintf("cannot conver %s to string", val)) - } - - t, err2 := time.Parse(time.UnixDate, str) - if err2 != nil { - tctx.L().Warn(fmt.Sprintf("cannot parse %s to time: %s", str, err2)) - } else { - // mock upstream instance restart from 5-20s - startTime := t.Add(5 * time.Second) - endTime := startTime.Add(20 * time.Second) - now := time.Now() - if now.Before(endTime) && now.After(startTime) { - tctx.L().Info("mock upstream instance restart", zap.String("failpoint", "SyncerGetEventError"), zap.Stringer("startTime", startTime), zap.Stringer("endTime", endTime)) - failpoint.Return(nil, terror.ErrDBBadConn.Generate()) - } + failpoint.Inject("SyncerGetEventError", func(_ failpoint.Value) { + if !mockRestarted { + mockRestarted = true + tctx.L().Info("mock upstream instance restart", zap.String("failpoint", "SyncerGetEventError")) + failpoint.Return(nil, terror.ErrDBBadConn.Generate()) } }) diff --git a/tests/drop_column_with_index/run.sh b/tests/drop_column_with_index/run.sh index 6749e4b00b..242505c190 100755 --- a/tests/drop_column_with_index/run.sh +++ b/tests/drop_column_with_index/run.sh @@ -9,8 +9,7 @@ WORK_DIR=$TEST_DIR/$TEST_NAME function run() { run_sql_file $cur/data/db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 - now=$(date) - export GO_FAILPOINTS="github.com/pingcap/dm/syncer/SyncerGetEventError=return(\"$now\")" + export GO_FAILPOINTS="github.com/pingcap/dm/syncer/SyncerGetEventError=return" # start DM worker and master run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml @@ -35,7 +34,7 @@ function run() { run_sql_file $cur/data/db1.increment.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 # use sync_diff_inspector to check data now! - check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 30 + check_sync_diff $WORK_DIR $cur/conf/diff_config.toml # check column covered by multi-column indices won't drop, and its indices won't drop run_sql "alter table drop_column_with_index.t1 drop column c2;" $MYSQL_PORT1 $MYSQL_PASSWORD1