Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing race condition in discovery test. #3213

Merged
merged 1 commit into from
Sep 20, 2017
Merged
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
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