MCPcopy
hub / github.com/klauspost/compress / TestNewDecoderFlushed

Function TestNewDecoderFlushed

zstd/decoder_test.go:620–680  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

618}
619
620func TestNewDecoderFlushed(t *testing.T) {
621 if testing.Short() {
622 t.SkipNow()
623 }
624 file := "testdata/z000028.zst"
625 payload, err := os.ReadFile(file)
626 if err != nil {
627 t.Fatal(err)
628 }
629 payload = append(payload, payload...) //2x
630 payload = append(payload, payload...) //4x
631 payload = append(payload, payload...) //8x
632 rng := rand.New(rand.NewSource(0x1337))
633 runs := 100
634 if testing.Short() {
635 runs = 5
636 }
637 enc, err := NewWriter(nil, WithWindowSize(128<<10))
638 if err != nil {
639 t.Fatal(err)
640 }
641 defer enc.Close()
642 for i := 0; i < runs; i++ {
643 wantSize := rng.Intn(len(payload)-1) + 1
644 t.Run(fmt.Sprint("size-", wantSize), func(t *testing.T) {
645 var encoded bytes.Buffer
646 enc.Reset(&encoded)
647 _, err := enc.Write(payload[:wantSize])
648 if err != nil {
649 t.Fatal(err)
650 }
651 err = enc.Flush()
652 if err != nil {
653 t.Fatal(err)
654 }
655
656 // We must be able to read back up until the flush...
657 r := readAndBlock{
658 buf: encoded.Bytes(),
659 unblock: make(chan struct{}),
660 }
661 defer timeout(5 * time.Second)()
662 dec, err := NewReader(&r)
663 if err != nil {
664 t.Fatal(err)
665 }
666 defer dec.Close()
667 defer close(r.unblock)
668 readBack := 0
669 dst := make([]byte, 1024)
670 for readBack < wantSize {
671 // Read until we have enough.
672 n, err := dec.Read(dst)
673 if err != nil {
674 t.Fatal(err)
675 }
676 readBack += n
677 }

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
ResetMethod · 0.95
WriteMethod · 0.95
FlushMethod · 0.95
CloseMethod · 0.95
ReadMethod · 0.95
WithWindowSizeFunction · 0.85
timeoutFunction · 0.85
FatalMethod · 0.80
NewWriterFunction · 0.70
NewReaderFunction · 0.70
BytesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…