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

Method TestDecompress_NoReadAfterEOF

rpc_util_test.go:581–612  ·  view source on GitHub ↗

Tests that the decompressor's Read method is not called after it returns EOF.

(t *testing.T)

Source from the content-addressed store, hash-verified

579
580// Tests that the decompressor's Read method is not called after it returns EOF.
581func (s) TestDecompress_NoReadAfterEOF(t *testing.T) {
582 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
583 defer cancel()
584
585 ch := make(chan struct{}, 10)
586 mc := &mockCompressor{ch: ch}
587 in := mem.BufferSlice{mem.NewBuffer(&[]byte{1, 2, 3}, nil)}
588 wg := sync.WaitGroup{}
589 wg.Add(1)
590 go func() {
591 defer wg.Done()
592 out, err := decompress(mc, in, nil, 1, mem.DefaultBufferPool())
593 if err != nil {
594 t.Errorf("Unexpected error from decompress: %v", err)
595 return
596 }
597 out.Free()
598 }()
599 select {
600 case <-ch:
601 case <-ctx.Done():
602 t.Fatalf("Timed out waiting for call to compressor")
603 }
604 ctx, cancel = context.WithTimeout(ctx, defaultTestShortTimeout)
605 defer cancel()
606 select {
607 case <-ch:
608 t.Fatalf("Unexpected second compressor.Read call detected")
609 case <-ctx.Done():
610 }
611 wg.Wait()
612}
613
614type fakeCloseCompressor struct {
615 encoding.Compressor

Callers

nothing calls this directly

Calls 9

NewBufferFunction · 0.92
DefaultBufferPoolFunction · 0.92
decompressFunction · 0.85
WaitMethod · 0.80
AddMethod · 0.65
ErrorfMethod · 0.65
FreeMethod · 0.65
FatalfMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected