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

Method TestStreamCleanup

test/stream_cleanup_test.go:36–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34)
35
36func (s) TestStreamCleanup(t *testing.T) {
37 const initialWindowSize uint = 70 * 1024 // Must be higher than default 64K, ignored otherwise
38 const bodySize = 2 * initialWindowSize // Something that is not going to fit in a single window
39 const callRecvMsgSize uint = 1 // The maximum message size the client can receive
40
41 ss := &stubserver.StubServer{
42 UnaryCallF: func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
43 return &testpb.SimpleResponse{Payload: &testpb.Payload{
44 Body: make([]byte, bodySize),
45 }}, nil
46 },
47 EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) {
48 return &testpb.Empty{}, nil
49 },
50 }
51 if err := ss.Start(nil, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(int(callRecvMsgSize))), grpc.WithInitialWindowSize(int32(initialWindowSize))); err != nil {
52 t.Fatalf("Error starting endpoint server: %v", err)
53 }
54 defer ss.Stop()
55
56 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
57 defer cancel()
58 if _, err := ss.Client.UnaryCall(ctx, &testpb.SimpleRequest{}); status.Code(err) != codes.ResourceExhausted {
59 t.Fatalf("should fail with ResourceExhausted, message's body size: %v, maximum message size the client can receive: %v", bodySize, callRecvMsgSize)
60 }
61 if _, err := ss.Client.EmptyCall(ctx, &testpb.Empty{}); err != nil {
62 t.Fatalf("should succeed, err: %v", err)
63 }
64}
65
66func (s) TestStreamCleanupAfterSendStatus(t *testing.T) {
67 const initialWindowSize uint = 70 * 1024 // Must be higher than default 64K, ignored otherwise

Callers

nothing calls this directly

Calls 9

StartMethod · 0.95
StopMethod · 0.95
WithDefaultCallOptionsFunction · 0.92
MaxCallRecvMsgSizeFunction · 0.92
WithInitialWindowSizeFunction · 0.92
CodeFunction · 0.92
FatalfMethod · 0.65
UnaryCallMethod · 0.65
EmptyCallMethod · 0.65

Tested by

no test coverage detected