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{})
| 221 | // Therefore, we do not return an error when the RPC fails. Instead, we wait for |
| 222 | // the context to expire before failing. |
| 223 | func 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 |
no test coverage detected