Skip to content

Commit

Permalink
Merge pull request #3213 from alainjobart/disco
Browse files Browse the repository at this point in the history
Fixing race condition in discovery test.
  • Loading branch information
sougou authored Sep 20, 2017
2 parents 990e8c9 + 4b94753 commit 80a5d4b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion go/vt/discovery/topology_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func checkWatcher(t *testing.T, cellTablets bool) {
t.Logf(`tw = ShardReplicationWatcher(topo.Server{ft}, fhc, "aa", "keyspace", "shard", 10ms, 5)`)
}

// Wait for the initial topology load to finish. Otherwise we
// have a background loadTablets() that's running, and it can
// interact with our tests in weird ways.
if err := tw.WaitForInitialTopology(); err != nil {
t.Fatalf("initial WaitForInitialTopology failed")
}

// add a tablet to the topology
ft.AddTablet("aa", 0, "host1", map[string]int32{"vt": 123})
tw.loadTablets()
Expand Down Expand Up @@ -198,7 +205,16 @@ func (ft *fakeTopo) GetShardReplication(ctx context.Context, cell, keyspace, sha
func (ft *fakeTopo) GetTablet(ctx context.Context, alias *topodatapb.TabletAlias) (*topodatapb.Tablet, int64, error) {
ft.mu.RLock()
defer ft.mu.RUnlock()
return ft.tablets[topoproto.TabletAliasString(alias)], 0, nil
// Note we want to be correct here. The way we call this, we never
// change the tablet list in between a call to list them,
// and a call to get the record, so we could just blindly return it.
// (It wasn't the case before we added the WaitForInitialTopology()
// call in the test though!).
tablet, ok := ft.tablets[topoproto.TabletAliasString(alias)]
if !ok {
return nil, 0, topo.ErrNoNode
}
return tablet, 0, nil
}

func TestFilterByShard(t *testing.T) {
Expand Down

0 comments on commit 80a5d4b

Please sign in to comment.