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

Method TestDecompress_ClosesReader

rpc_util_test.go:636–676  ·  view source on GitHub ↗

TestDecompress_ClosesReader tests that the reader returned by Decompress is closed when decompress returns.

(t *testing.T)

Source from the content-addressed store, hash-verified

634// TestDecompress_ClosesReader tests that the reader returned by Decompress is
635// closed when decompress returns.
636func (s) TestDecompress_ClosesReader(t *testing.T) {
637 testCases := []struct {
638 name string
639 maxReceiveMessageSize int
640 wantCode codes.Code
641 }{
642 {
643 name: "close_on_failure",
644 maxReceiveMessageSize: 1,
645 wantCode: codes.ResourceExhausted,
646 },
647 {
648 name: "close_on_success",
649 maxReceiveMessageSize: 100,
650 wantCode: codes.OK,
651 },
652 }
653
654 for _, tc := range testCases {
655 t.Run(tc.name, func(t *testing.T) {
656 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
657 defer cancel()
658
659 ch := make(chan struct{})
660 compressor := &fakeCloseCompressor{ch: ch}
661 in := mustCompress(t, []byte("some data"))
662 out, err := decompress(compressor, in, nil, tc.maxReceiveMessageSize, mem.DefaultBufferPool())
663 if status.Code(err) != tc.wantCode {
664 t.Fatalf("decompress() failed with error code %v, want %v", status.Code(err), tc.wantCode)
665 }
666
667 out.Free()
668
669 select {
670 case <-ch:
671 case <-ctx.Done():
672 t.Fatalf("Timed out waiting for Close to be called")
673 }
674 })
675 }
676}

Callers

nothing calls this directly

Calls 7

DefaultBufferPoolFunction · 0.92
CodeFunction · 0.92
mustCompressFunction · 0.85
decompressFunction · 0.85
FatalfMethod · 0.65
FreeMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected