MCPcopy
hub / github.com/grpc/grpc-go / waitForTrafficToReachBackends

Function waitForTrafficToReachBackends

internal/testutils/roundrobin/roundrobin.go:46–77  ·  view source on GitHub ↗

waitForTrafficToReachBackends repeatedly makes RPCs using the provided TestServiceClient until RPCs reach all backends specified in addrs, or the context expires, in which case a non-nil error is returned.

(ctx context.Context, client testgrpc.TestServiceClient, addrs []resolver.Address)

Source from the content-addressed store, hash-verified

44// TestServiceClient until RPCs reach all backends specified in addrs, or the
45// context expires, in which case a non-nil error is returned.
46func waitForTrafficToReachBackends(ctx context.Context, client testgrpc.TestServiceClient, addrs []resolver.Address) error {
47 // Make sure connections to all backends are up. We need to do this two
48 // times (to be sure that round_robin has kicked in) because the channel
49 // could have been configured with a different LB policy before the switch
50 // to round_robin. And the previous LB policy could be sharing backends with
51 // round_robin, and therefore in the first iteration of this loop, RPCs
52 // could land on backends owned by the previous LB policy.
53 for j := 0; j < 2; j++ {
54 for i := 0; i < len(addrs); i++ {
55 for {
56 time.Sleep(time.Millisecond)
57 if ctx.Err() != nil {
58 return fmt.Errorf("timeout waiting for connection to %q to be up", addrs[i].Addr)
59 }
60 var peer peer.Peer
61 if _, err := client.EmptyCall(ctx, &testpb.Empty{}, grpc.Peer(&peer)); err != nil {
62 // Some tests remove backends and check if round robin is
63 // happening across the remaining backends. In such cases,
64 // RPCs can initially fail on the connection using the
65 // removed backend. Just keep retrying and eventually the
66 // connection using the removed backend will shutdown and
67 // will be removed.
68 continue
69 }
70 if peer.Addr.String() == addrs[i].Addr {
71 break
72 }
73 }
74 }
75 }
76 return nil
77}
78
79// CheckRoundRobinRPCs verifies that EmptyCall RPCs on the given ClientConn,
80// connected to a server exposing the test.grpc_testing.TestService, are

Callers 2

CheckRoundRobinRPCsFunction · 0.85

Calls 5

PeerFunction · 0.92
ErrMethod · 0.80
ErrorfMethod · 0.65
EmptyCallMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected