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

Function runPingPongTest

internal/transport/transport_test.go:2517–2563  ·  view source on GitHub ↗

This is a stress-test of flow control logic.

(t *testing.T, msgSize int)

Source from the content-addressed store, hash-verified

2515
2516// This is a stress-test of flow control logic.
2517func runPingPongTest(t *testing.T, msgSize int) {
2518 server, client, cancel := setUp(t, 0, pingpong)
2519 defer cancel()
2520 defer server.stop()
2521 defer client.Close(fmt.Errorf("closed manually by test"))
2522 waitWhileTrue(t, func() (bool, error) {
2523 server.mu.Lock()
2524 defer server.mu.Unlock()
2525 if len(server.conns) == 0 {
2526 return true, fmt.Errorf("timed out while waiting for server transport to be created")
2527 }
2528 return false, nil
2529 })
2530 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
2531 defer cancel()
2532 stream, err := client.NewStream(ctx, &CallHdr{}, nil)
2533 if err != nil {
2534 t.Fatalf("Failed to create stream. Err: %v", err)
2535 }
2536 msg := make([]byte, msgSize)
2537 outgoingHeader := make([]byte, 5)
2538 outgoingHeader[0] = byte(0)
2539 binary.BigEndian.PutUint32(outgoingHeader[1:], uint32(msgSize))
2540 opts := &WriteOptions{}
2541 incomingHeader := make([]byte, 5)
2542
2543 ctx, cancel = context.WithTimeout(ctx, 10*time.Millisecond)
2544 defer cancel()
2545 for ctx.Err() == nil {
2546 if err := stream.Write(outgoingHeader, newBufferSlice(msg), opts); err != nil {
2547 t.Fatalf("Error on client while writing message. Err: %v", err)
2548 }
2549 if _, err := stream.readTo(incomingHeader); err != nil {
2550 t.Fatalf("Error on client while reading data header. Err: %v", err)
2551 }
2552 sz := binary.BigEndian.Uint32(incomingHeader[1:])
2553 recvMsg := make([]byte, int(sz))
2554 if _, err := stream.readTo(recvMsg); err != nil {
2555 t.Fatalf("Error on client while reading data. Err: %v", err)
2556 }
2557 }
2558
2559 stream.Write(nil, nil, &WriteOptions{Last: true})
2560 if _, err := stream.readTo(incomingHeader); err != io.EOF {
2561 t.Fatalf("Client expected EOF from the server. Got: %v", err)
2562 }
2563}
2564
2565type tableSizeLimit struct {
2566 mu sync.Mutex

Callers 4

TestPingPong1BMethod · 0.85
TestPingPong1KBMethod · 0.85
TestPingPong64KBMethod · 0.85
TestPingPong1MBMethod · 0.85

Calls 13

readToMethod · 0.95
setUpFunction · 0.85
waitWhileTrueFunction · 0.85
newBufferSliceFunction · 0.85
ErrMethod · 0.80
stopMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65
NewStreamMethod · 0.65
FatalfMethod · 0.65
WriteMethod · 0.65
LockMethod · 0.45

Tested by

no test coverage detected