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

Method TestDecompressionExceedsMaxMessageSize

encoding/compressor_test.go:215–239  ·  view source on GitHub ↗

TestDecompressionExceedsMaxMessageSize uses a fake compressor that produces messages of size 100 bytes on decompression. A server is started with the max receive message size restricted to 99 bytes. The test verifies that the client receives a ResourceExhausted response from the server.

(t *testing.T)

Source from the content-addressed store, hash-verified

213// max receive message size restricted to 99 bytes. The test verifies that the
214// client receives a ResourceExhausted response from the server.
215func (s) TestDecompressionExceedsMaxMessageSize(t *testing.T) {
216 const messageLen = 100
217 regFn := internal.RegisterCompressorForTesting.(func(encoding.Compressor) func())
218 compressor := &fakeCompressor{decompressedMessageSize: messageLen}
219 unreg := regFn(compressor)
220 defer unreg()
221 ss := &stubserver.StubServer{
222 UnaryCallF: func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
223 return &testpb.SimpleResponse{}, nil
224 },
225 }
226 if err := ss.Start([]grpc.ServerOption{grpc.MaxRecvMsgSize(messageLen - 1)}); err != nil {
227 t.Fatalf("Error starting endpoint server: %v", err)
228 }
229 defer ss.Stop()
230
231 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
232 defer cancel()
233
234 req := &testpb.SimpleRequest{Payload: &testpb.Payload{}}
235 _, err := ss.Client.UnaryCall(ctx, req, grpc.UseCompressor(compressor.Name()))
236 if got, want := status.Code(err), codes.ResourceExhausted; got != want {
237 t.Errorf("Client.UnaryCall(%+v) returned status %v, want %v", req, got, want)
238 }
239}

Callers

nothing calls this directly

Calls 9

StartMethod · 0.95
StopMethod · 0.95
NameMethod · 0.95
MaxRecvMsgSizeFunction · 0.92
UseCompressorFunction · 0.92
CodeFunction · 0.92
FatalfMethod · 0.65
UnaryCallMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected