Tests that the decompressor's Read method is not called after it returns EOF.
(t *testing.T)
| 579 | |
| 580 | // Tests that the decompressor's Read method is not called after it returns EOF. |
| 581 | func (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 | |
| 614 | type fakeCloseCompressor struct { |
| 615 | encoding.Compressor |
nothing calls this directly
no test coverage detected