diff --git a/zstd/seqdec_test.go b/zstd/seqdec_test.go index 0e07adf638..fc9470f4eb 100644 --- a/zstd/seqdec_test.go +++ b/zstd/seqdec_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/csv" "fmt" + "io" "io/ioutil" "os" "reflect" @@ -167,6 +168,35 @@ func readDecoders(tb testing.TB, buf *bytes.Buffer, ref testSequence) sequenceDe return s } +func Test_seqdec_decode_regression(t *testing.T) { + zr := testCreateZipReader("testdata/decode-regression.zip", t) + + for _, tt := range zr.File { + t.Run(tt.Name, func(t *testing.T) { + f, err := tt.Open() + if err != nil { + t.Error(err) + return + } + defer f.Close() + + // Note: make sure we create stream reader + dec, err := NewReader(f, WithDecoderConcurrency(4)) + if err != nil { + t.Error(err) + return + } + + var buf []byte + _, err = io.ReadFull(dec, buf) + if err != nil { + t.Error(err) + return + } + }) + } +} + func Test_seqdec_decoder(t *testing.T) { const writeWant = false var buf bytes.Buffer @@ -175,16 +205,8 @@ func Test_seqdec_decoder(t *testing.T) { want := map[string][]seqVals{} var wantOffsets = map[string][3]int{} if !writeWant { - fn := "testdata/seqs-want.zip" - data, err := ioutil.ReadFile(fn) + zr := testCreateZipReader("testdata/seqs-want.zip", t) tb := t - if err != nil { - tb.Fatal(err) - } - zr, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) - if err != nil { - tb.Fatal(err) - } for _, tt := range zr.File { var ref testSequence if !ref.parse(tt.Name) { @@ -217,16 +239,8 @@ func Test_seqdec_decoder(t *testing.T) { o.Close() } } - fn := "testdata/seqs.zip" - data, err := ioutil.ReadFile(fn) + zr := testCreateZipReader("testdata/seqs.zip", t) tb := t - if err != nil { - tb.Fatal(err) - } - zr, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) - if err != nil { - tb.Fatal(err) - } for _, tt := range zr.File { var ref testSequence if !ref.parse(tt.Name) { @@ -289,16 +303,8 @@ func Test_seqdec_decoder(t *testing.T) { } func Test_seqdec_execute(t *testing.T) { - fn := "testdata/seqs.zip" - data, err := ioutil.ReadFile(fn) + zr := testCreateZipReader("testdata/seqs.zip", t) tb := t - if err != nil { - tb.Fatal(err) - } - zr, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) - if err != nil { - tb.Fatal(err) - } for _, tt := range zr.File { var ref testSequence if !ref.parse(tt.Name) { @@ -350,16 +356,8 @@ func Test_seqdec_execute(t *testing.T) { } func Test_seqdec_decodeSync(t *testing.T) { - fn := "testdata/seqs.zip" - data, err := ioutil.ReadFile(fn) + zr := testCreateZipReader("testdata/seqs.zip", t) tb := t - if err != nil { - tb.Fatal(err) - } - zr, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) - if err != nil { - tb.Fatal(err) - } for _, tt := range zr.File { var ref testSequence if !ref.parse(tt.Name) { @@ -408,16 +406,8 @@ func Benchmark_seqdec_decode(b *testing.B) { } func benchmark_seqdec_decode(b *testing.B) { - fn := "testdata/seqs.zip" - data, err := ioutil.ReadFile(fn) + zr := testCreateZipReader("testdata/seqs.zip", b) tb := b - if err != nil { - tb.Fatal(err) - } - zr, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) - if err != nil { - tb.Fatal(err) - } for _, tt := range zr.File { var ref testSequence if !ref.parse(tt.Name) { @@ -468,16 +458,8 @@ func benchmark_seqdec_decode(b *testing.B) { } func Benchmark_seqdec_execute(b *testing.B) { - fn := "testdata/seqs.zip" - data, err := ioutil.ReadFile(fn) + zr := testCreateZipReader("testdata/seqs.zip", b) tb := b - if err != nil { - tb.Fatal(err) - } - zr, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) - if err != nil { - tb.Fatal(err) - } for _, tt := range zr.File { var ref testSequence if !ref.parse(tt.Name) { @@ -532,16 +514,8 @@ func Benchmark_seqdec_execute(b *testing.B) { } func Benchmark_seqdec_decodeSync(b *testing.B) { - fn := "testdata/seqs.zip" - data, err := ioutil.ReadFile(fn) + zr := testCreateZipReader("testdata/seqs.zip", b) tb := b - if err != nil { - tb.Fatal(err) - } - zr, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) - if err != nil { - tb.Fatal(err) - } for _, tt := range zr.File { var ref testSequence if !ref.parse(tt.Name) { @@ -594,3 +568,19 @@ func Benchmark_seqdec_decodeSync(b *testing.B) { }) } } + +func testCreateZipReader(path string, tb testing.TB) *zip.Reader { + failOnError := func(err error) { + if err != nil { + tb.Fatal(err) + } + } + + data, err := ioutil.ReadFile(path) + failOnError(err) + + zr, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) + failOnError(err) + + return zr +} diff --git a/zstd/testdata/decode-regression.zip b/zstd/testdata/decode-regression.zip new file mode 100644 index 0000000000..9ea27c8ded Binary files /dev/null and b/zstd/testdata/decode-regression.zip differ