Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

test: remove wait time to reduce indetermination #922

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions syncer/streamer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package syncer

import (
"context"
"fmt"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only fail in some times previously or only restart once is enough, @GMHDBJD this new implement can achieve your purpose?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enough

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())
}
})

Expand Down
5 changes: 2 additions & 3 deletions tests/drop_column_with_index/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down