Skip to content

Commit

Permalink
Merge pull request #5620 from planetscale/ss-deflake-migrater
Browse files Browse the repository at this point in the history
tests: deflake migrater
  • Loading branch information
sougou authored Dec 23, 2019
2 parents 434af95 + 64fd6ff commit 484003c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions go/vt/wrangler/migrater.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ func (wr *Wrangler) buildMigrationTargets(ctx context.Context, targetKeyspace, w
if err != nil {
return nil, false, err
}
if targetsi.MasterAlias == nil {
// This can happen if bad inputs are given.
return nil, false, fmt.Errorf("shard %v:%v doesn't have a master set", targetKeyspace, targetShard)
}
targetMaster, err := wr.ts.GetTablet(ctx, targetsi.MasterAlias)
if err != nil {
return nil, false, err
Expand Down
23 changes: 20 additions & 3 deletions go/vt/wrangler/migrater_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package wrangler
import (
"fmt"
"testing"
"time"

"golang.org/x/net/context"
"vitess.io/vitess/go/mysql"
Expand Down Expand Up @@ -292,11 +293,27 @@ func newTestShardMigrater(ctx context.Context, t *testing.T, sourceShards, targe
}

func (tme *testMigraterEnv) startTablets(t *testing.T) {
for _, master := range tme.sourceMasters {
allMasters := append(tme.sourceMasters, tme.targetMasters...)
for _, master := range allMasters {
master.StartActionLoop(t, tme.wr)
}
for _, master := range tme.targetMasters {
master.StartActionLoop(t, tme.wr)
// Wait for the shard record masters to be set.
for _, master := range allMasters {
masterFound := false
for i := 0; i < 10; i++ {
si, err := tme.wr.ts.GetShard(context.Background(), master.Tablet.Keyspace, master.Tablet.Shard)
if err != nil {
t.Fatal(err)
}
if si.MasterAlias != nil {
masterFound = true
break
}
time.Sleep(10 * time.Millisecond)
}
if !masterFound {
t.Fatalf("shard master did not get updated for tablet: %v", master)
}
}
}

Expand Down

0 comments on commit 484003c

Please sign in to comment.