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

testutils: do a better job of verifying pick_first in tests #5850

Merged
merged 1 commit into from Dec 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions internal/testutils/pickfirst/pickfirst.go
Expand Up @@ -41,7 +41,12 @@ import (
func CheckRPCsToBackend(ctx context.Context, cc *grpc.ClientConn, wantAddr resolver.Address) error {
client := testgrpc.NewTestServiceClient(cc)
peer := &peer.Peer{}
// Make sure the RPC reaches the expected backend once.
// Make sure that 20 RPCs in a row reach the expected backend. Some
// tests switch from round_robin back to pick_first and call this
// function. None of our tests spin up more than 10 backends. So,
// waiting for 20 RPCs to reach a single backend would a decent
// indicator of having switched to pick_first.
count := 0
for {
time.Sleep(time.Millisecond)
if ctx.Err() != nil {
Expand All @@ -55,7 +60,12 @@ func CheckRPCsToBackend(ctx context.Context, cc *grpc.ClientConn, wantAddr resol
// removed.
continue
}
if peer.Addr.String() == wantAddr.Addr {
if peer.Addr.String() != wantAddr.Addr {
count = 0
continue
}
count++
if count > 20 {
break
}
}
Expand Down