Skip to content

Commit

Permalink
Add regression test for #561 (#564)
Browse files Browse the repository at this point in the history
* zstd: factor out zip reader creation to a helper function
* zstd: add regression case for #561
  • Loading branch information
WojciechMula authored Apr 22, 2022
1 parent aa5b572 commit 4e8b280
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 63 deletions.
116 changes: 53 additions & 63 deletions zstd/seqdec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/csv"
"fmt"
"io"
"io/ioutil"
"os"
"reflect"
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Binary file added zstd/testdata/decode-regression.zip
Binary file not shown.

0 comments on commit 4e8b280

Please sign in to comment.