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

Function makeTestRPCAndExpectItToReachBackend

balancer/rls/helpers_test.go:223–248  ·  view source on GitHub ↗

makeTestRPCAndExpectItToReachBackend is a test helper function which makes the EmptyCall RPC on the given ClientConn and verifies that it reaches a backend. The latter is accomplished by listening on the provided channel which gets pushed to whenever the backend in question gets an RPC. There are m

(ctx context.Context, t *testing.T, cc *grpc.ClientConn, ch chan struct{})

Source from the content-addressed store, hash-verified

221// Therefore, we do not return an error when the RPC fails. Instead, we wait for
222// the context to expire before failing.
223func makeTestRPCAndExpectItToReachBackend(ctx context.Context, t *testing.T, cc *grpc.ClientConn, ch chan struct{}) {
224 t.Helper()
225
226 // Drain the backend channel before performing the RPC to remove any
227 // notifications from previous RPCs.
228 select {
229 case <-ch:
230 default:
231 }
232
233 for {
234 if err := ctx.Err(); err != nil {
235 t.Fatalf("Timeout when waiting for RPCs to be routed to the given target: %v", err)
236 }
237 sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout)
238 client := testgrpc.NewTestServiceClient(cc)
239 client.EmptyCall(sCtx, &testpb.Empty{})
240
241 select {
242 case <-sCtx.Done():
243 case <-ch:
244 sCancel()
245 return
246 }
247 }
248}
249
250// makeTestRPCAndVerifyError is a test helper function which makes the EmptyCall
251// RPC on the given ClientConn and verifies that the RPC fails with the given

Calls 4

EmptyCallMethod · 0.95
ErrMethod · 0.80
FatalfMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected