diff --git a/go/vt/vttablet/tabletmanager/vreplication/vplayer_test.go b/go/vt/vttablet/tabletmanager/vreplication/vplayer_test.go index 5abc68b0b3c..85cc516c2a9 100644 --- a/go/vt/vttablet/tabletmanager/vreplication/vplayer_test.go +++ b/go/vt/vttablet/tabletmanager/vreplication/vplayer_test.go @@ -24,6 +24,8 @@ import ( "testing" "time" + "vitess.io/vitess/go/vt/log" + "golang.org/x/net/context" "vitess.io/vitess/go/sqltypes" @@ -1113,10 +1115,9 @@ func TestPlayerDDL(t *testing.T) { OnDdl: binlogdatapb.OnDDLAction_STOP, } cancel, id := startVReplication(t, bls, "") + pos0 := masterPosition(t) //For debugging only execStatements(t, []string{"alter table t1 add column val varchar(128)"}) pos1 := masterPosition(t) - execStatements(t, []string{"alter table t1 drop column val"}) - pos2 := masterPosition(t) // The stop position must be the GTID of the first DDL expectDBClientQueries(t, []string{ "begin", @@ -1124,6 +1125,11 @@ func TestPlayerDDL(t *testing.T) { "/update _vt.vreplication set state='Stopped'", "commit", }) + pos2b := masterPosition(t) + execStatements(t, []string{"alter table t1 drop column val"}) + pos2 := masterPosition(t) + log.Errorf("Expected log:: TestPlayerDDL Positions are: before first alter %v, after first alter %v, before second alter %v, after second alter %v", + pos0, pos1, pos2b, pos2) //For debugging only: to check what are the positions when test works and if/when it fails // Restart vreplication if _, err := playerEngine.Exec(fmt.Sprintf(`update _vt.vreplication set state = 'Running', message='' where id=%d`, id)); err != nil { t.Fatal(err) diff --git a/go/vt/vttablet/tabletmanager/vreplication/vstreamer_client_test.go b/go/vt/vttablet/tabletmanager/vreplication/vstreamer_client_test.go index d52703a6e8f..af3e762383b 100644 --- a/go/vt/vttablet/tabletmanager/vreplication/vstreamer_client_test.go +++ b/go/vt/vttablet/tabletmanager/vreplication/vstreamer_client_test.go @@ -250,13 +250,14 @@ func TestTabletVStreamerClientVStreamRows(t *testing.T) { defer vsClient.Close(ctx) - // This asserts that events are flowing through the VStream when using mysql client - go vsClient.VStreamRows(ctx, "select * from t1", nil, send) - execStatements(t, []string{ fmt.Sprintf("insert into t1 values(1, '%s', '%s')", want, want), }) + // This asserts that events are flowing through VStreamRows when using mysql client + // This needs to happen after the insert above to avoid race where select precedes the insert + go vsClient.VStreamRows(ctx, "select * from t1", nil, send) + select { case <-eventsChan: // Success got expected