Skip to content

Commit 5003029

Browse files
authored
testutils: do a better job of verifying pick_first in tests (#5850)
1 parent 3e27f89 commit 5003029

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

internal/testutils/pickfirst/pickfirst.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ import (
4141
func CheckRPCsToBackend(ctx context.Context, cc *grpc.ClientConn, wantAddr resolver.Address) error {
4242
client := testgrpc.NewTestServiceClient(cc)
4343
peer := &peer.Peer{}
44-
// Make sure the RPC reaches the expected backend once.
44+
// Make sure that 20 RPCs in a row reach the expected backend. Some
45+
// tests switch from round_robin back to pick_first and call this
46+
// function. None of our tests spin up more than 10 backends. So,
47+
// waiting for 20 RPCs to reach a single backend would a decent
48+
// indicator of having switched to pick_first.
49+
count := 0
4550
for {
4651
time.Sleep(time.Millisecond)
4752
if ctx.Err() != nil {
@@ -55,7 +60,12 @@ func CheckRPCsToBackend(ctx context.Context, cc *grpc.ClientConn, wantAddr resol
5560
// removed.
5661
continue
5762
}
58-
if peer.Addr.String() == wantAddr.Addr {
63+
if peer.Addr.String() != wantAddr.Addr {
64+
count = 0
65+
continue
66+
}
67+
count++
68+
if count > 20 {
5969
break
6070
}
6171
}

0 commit comments

Comments
 (0)