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

Function testPeerFailedRPC

test/end2end_test.go:2447–2496  ·  view source on GitHub ↗
(t *testing.T, e env)

Source from the content-addressed store, hash-verified

2445}
2446
2447func testPeerFailedRPC(t *testing.T, e env) {
2448 te := newTest(t, e)
2449 te.maxServerReceiveMsgSize = newInt(1 * 1024)
2450 te.startServer(&testServer{security: e.security})
2451
2452 defer te.tearDown()
2453 tc := testgrpc.NewTestServiceClient(te.clientConn())
2454
2455 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
2456 defer cancel()
2457 // first make a successful request to the server
2458 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); err != nil {
2459 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, <nil>", err)
2460 }
2461
2462 // make a second request that will be rejected by the server
2463 const largeSize = 5 * 1024
2464 largePayload, err := newPayload(testpb.PayloadType_COMPRESSABLE, largeSize)
2465 if err != nil {
2466 t.Fatal(err)
2467 }
2468 req := &testpb.SimpleRequest{
2469 ResponseType: testpb.PayloadType_COMPRESSABLE,
2470 Payload: largePayload,
2471 }
2472
2473 peer := new(peer.Peer)
2474 if _, err := tc.UnaryCall(ctx, req, grpc.Peer(peer)); err == nil || status.Code(err) != codes.ResourceExhausted {
2475 t.Fatalf("TestService/UnaryCall(_, _) = _, %v, want _, error code: %s", err, codes.ResourceExhausted)
2476 } else {
2477 pa := peer.Addr.String()
2478 if e.network == "unix" {
2479 if pa != te.srvAddr {
2480 t.Fatalf("peer.Addr = %v, want %v", pa, te.srvAddr)
2481 }
2482 return
2483 }
2484 _, pp, err := net.SplitHostPort(pa)
2485 if err != nil {
2486 t.Fatalf("Failed to parse address from peer.")
2487 }
2488 _, sp, err := net.SplitHostPort(te.srvAddr)
2489 if err != nil {
2490 t.Fatalf("Failed to parse address of test server.")
2491 }
2492 if pp != sp {
2493 t.Fatalf("peer.Addr = localhost:%v, want localhost:%v", pp, sp)
2494 }
2495 }
2496}
2497
2498func (s) TestMetadataUnaryRPC(t *testing.T) {
2499 for _, e := range listTestEnv() {

Callers 1

TestPeerFailedRPCMethod · 0.85

Calls 13

EmptyCallMethod · 0.95
UnaryCallMethod · 0.95
PeerFunction · 0.92
newPayloadFunction · 0.85
CodeMethod · 0.80
newTestFunction · 0.70
newIntFunction · 0.70
FatalfMethod · 0.65
FatalMethod · 0.65
StringMethod · 0.65
startServerMethod · 0.45
tearDownMethod · 0.45

Tested by

no test coverage detected