Skip to content

Commit

Permalink
fix test with helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Hahn authored and felipejfc committed Nov 13, 2019
1 parent b97a96c commit dd773c9
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions cluster/etcd_service_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,18 +434,34 @@ func TestEtcdWatchChangesWithBlacklist(t *testing.T) {
assert.NoError(t, err)
}

// We sleep here to guarantee that the watch callback is called. However, the etcd server is in memory,
// so the callback is really fast. The time here is an upper bound.
time.Sleep(time.Millisecond * 500)
numRequiredServersInSd := func() int {
num := 0
for _, serverToAdd := range table.serversToAdd {
if !e.isServerTypeBlacklisted(serverToAdd.Type) {
num++
}
}
return num + 1 // The server itself is always added to the cache, that's why we add one here
}

for _, serverToAdd := range table.serversToAdd {
_, err := e.GetServer(serverToAdd.ID)
if e.isServerTypeBlacklisted(serverToAdd.Type) {
assert.Error(t, err)
} else {
assert.NoError(t, err)
numServersInSd := func() int {
num := 0

_, err := e.GetServer(table.server.ID)
if err == nil {
num++
}
for _, serverToAdd := range table.serversToAdd {
_, err := e.GetServer(serverToAdd.ID)
if err == nil {
num++
}
}
println("Returning val ", num)
return num
}

helpers.ShouldEventuallyReturn(t, numServersInSd, numRequiredServersInSd())
})
}
}
Expand Down

0 comments on commit dd773c9

Please sign in to comment.