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)
| 213 | // max receive message size restricted to 99 bytes. The test verifies that the |
| 214 | // client receives a ResourceExhausted response from the server. |
| 215 | func (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 | } |
nothing calls this directly
no test coverage detected