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

[tests] Increase timeout for TestGRPCResolverRoundRobin #2729

Merged
merged 4 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
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
27 changes: 15 additions & 12 deletions pkg/discovery/grpcresolver/grpc_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,25 @@ func (r *Resolver) Close() {
r.closing.Wait()
}

// rendezvousHash is the core of the algorithm. It takes input addresses,
// assigns each of them a hash, sorts them by those hash values, and
// returns top N of entries from the sorted list, up to minPeers parameter.
func (r *Resolver) rendezvousHash(addresses []string) []string {
hasher := fnv.New32()
hosts := hostScores{}
for _, address := range addresses {
hosts = append(hosts, hostScore{
hosts := make(hostScores, len(addresses))
for i, address := range addresses {
hosts[i] = hostScore{
address: address,
score: hashAddr(hasher, []byte(address), r.salt),
})
}
}
sort.Sort(hosts)
size := min(r.discoveryMinPeers, len(hosts))
addressesPerHost := make([]string, size)
for i := 0; i < size; i++ {
addressesPerHost[i] = hosts[i].address
n := min(r.discoveryMinPeers, len(hosts))
topN := make([]string, n)
for i := 0; i < n; i++ {
topN[i] = hosts[i].address
}
return addressesPerHost
return topN
}

func min(a, b int) int {
Expand All @@ -162,9 +165,9 @@ func (r *Resolver) updateAddresses(hostPorts []string) {
}

func generateAddresses(instances []string) []resolver.Address {
var addrs []resolver.Address
for _, instance := range instances {
addrs = append(addrs, resolver.Address{Addr: instance})
addrs := make([]resolver.Address, len(instances))
for i, instance := range instances {
addrs[i] = resolver.Address{Addr: instance}
}
return addrs
}
12 changes: 8 additions & 4 deletions pkg/discovery/grpcresolver/grpc_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,20 @@ func makeSureConnectionsUp(t *testing.T, count int, testc grpctest.TestServiceCl
// Make sure connections to all servers are up.
for si := 0; si < count; si++ {
connected := false
for i := 0; i < 1000; i++ {
for i := 0; i < 3000; i++ { // 3000 * 10ms = 30s
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the main change/fix

_, err := testc.EmptyCall(context.Background(), &grpctest.Empty{}, grpc.Peer(&p))
if err != nil {
continue
}
if _, ok := addrs[p.Addr.String()]; !ok {
addrs[p.Addr.String()] = struct{}{}
connected = true
t.Logf("connected to peer #%d (%v) on iteration %d", si, p.Addr, i)
break
}
time.Sleep(time.Millisecond * 10)
}
assert.True(t, connected, "Connection was still not up")
assert.True(t, connected, "Connection #%d was still not up. Connections so far: %+v", si, addrs)
}
}

Expand Down Expand Up @@ -135,10 +136,13 @@ func TestGRPCResolverRoundRobin(t *testing.T) {
minPeers int
connections int // expected number of unique connections to servers
}{
{3, 3}, {5, 5}, {7, 5},
{minPeers: 3, connections: 3},
{minPeers: 5, connections: 3},
// note: test cannot succeed with minPeers < connections because resolver
// will never return more than minPeers addresses.
}
for _, test := range tests {
t.Run(fmt.Sprintf("minPeers=%d", test.minPeers), func(t *testing.T) {
t.Run(fmt.Sprintf("%+v", test), func(t *testing.T) {
res := New(notifier, discoverer, zap.NewNop(), test.minPeers)
defer resolver.UnregisterForTesting(res.Scheme())

Expand Down