Skip to content

Commit

Permalink
[tests] Increase timeout for TestGRPCResolverRoundRobin (jaegertracin…
Browse files Browse the repository at this point in the history
…g#2729)

* [tests] Add logging for TestGRPCResolverRoundRobin

Signed-off-by: Yuri Shkuro <github@ysh.us>

* rename var for clarity

Signed-off-by: Yuri Shkuro <github@ysh.us>

* cleanup

Signed-off-by: Yuri Shkuro <github@ysh.us>

* increase timeout

Signed-off-by: Yuri Shkuro <github@ysh.us>
  • Loading branch information
yurishkuro authored and bhiravabhatla committed Jan 25, 2021
1 parent b980e87 commit 5b80343
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
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
_, 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

0 comments on commit 5b80343

Please sign in to comment.