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

Function makeTestRPCAndVerifyError

balancer/rls/helpers_test.go:256–278  ·  view source on GitHub ↗

makeTestRPCAndVerifyError is a test helper function which makes the EmptyCall RPC on the given ClientConn and verifies that the RPC fails with the given status code and error. Similar to makeTestRPCAndExpectItToReachBackend, retries until expected outcome is reached or the provided context has expi

(ctx context.Context, t *testing.T, cc *grpc.ClientConn, wantCode codes.Code, wantErr error)

Source from the content-addressed store, hash-verified

254// Similar to makeTestRPCAndExpectItToReachBackend, retries until expected
255// outcome is reached or the provided context has expired.
256func makeTestRPCAndVerifyError(ctx context.Context, t *testing.T, cc *grpc.ClientConn, wantCode codes.Code, wantErr error) {
257 t.Helper()
258
259 for {
260 if err := ctx.Err(); err != nil {
261 t.Fatalf("Timeout when waiting for RPCs to fail with given error: %v", err)
262 }
263 sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout)
264 client := testgrpc.NewTestServiceClient(cc)
265 _, err := client.EmptyCall(sCtx, &testpb.Empty{})
266
267 // If the RPC fails with the expected code and expected error message (if
268 // one was provided), we return. Else we retry after blocking for a little
269 // while to ensure that we don't keep blasting away with RPCs.
270 if code := status.Code(err); code == wantCode {
271 if wantErr == nil || strings.Contains(err.Error(), wantErr.Error()) {
272 sCancel()
273 return
274 }
275 }
276 <-sCtx.Done()
277 }
278}
279
280// verifyRLSRequest is a test helper which listens on a channel to see if an RLS
281// request was received by the fake RLS server. Based on whether the test

Calls 6

EmptyCallMethod · 0.95
CodeFunction · 0.92
ErrMethod · 0.80
FatalfMethod · 0.65
ErrorMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected