From 0afc4af7e6baeb50bde166188d9e9cd1973c8a6f Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Fri, 19 Feb 2021 06:02:31 -0800 Subject: [PATCH] Upgrade to Go 1.16 (#321) * Upgrade to Go 1.16 * Disable cgo. * Faster race tests. --- .travis.yml | 11 ++-- flate/deflate_test.go | 3 ++ flate/flate_test.go | 121 ++++++++++++++++++++++-------------------- flate/writer_test.go | 3 ++ s2/encode_test.go | 3 ++ s2/s2_test.go | 6 +++ zstd/dict_test.go | 8 ++- zstd/encoder_test.go | 15 +++++- 8 files changed, 105 insertions(+), 65 deletions(-) diff --git a/.travis.yml b/.travis.yml index bba79d8cf0..0eaa7c4da4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,10 +8,11 @@ go: - 1.13.x - 1.14.x - 1.15.x + - 1.16.x - master env: - - GO111MODULE=off + - GO111MODULE=off CGO_ENABLED=0 install: - go get ./... @@ -21,7 +22,7 @@ script: - diff <(gofmt -d .) <(printf "") - go test -cpu=2 ./... - go test -cpu=2 -tags=noasm ./... - - go test -cpu=1,4 -short -race ./... + - CGO_ENABLED=1 go test -cpu=1,4 -short -race ./... - go build github.com/klauspost/compress/s2/cmd/s2c && go build github.com/klauspost/compress/s2/cmd/s2d && s2c s2c && s2d s2c.s2 && rm s2c && rm s2d && rm s2c.s2 jobs: @@ -30,18 +31,18 @@ jobs: fast_finish: true include: - stage: 386 linux test - go: 1.15.x + go: 1.16.x script: - GOOS=linux GOARCH=386 go test -short ./... deploy: - provider: script skip_cleanup: true - script: curl -sL https://git.io/goreleaser | VERSION=v0.127.0 bash || true + script: curl -sL https://git.io/goreleaser | VERSION=v0.157.0 bash || true on: tags: true condition: $TRAVIS_OS_NAME = linux - go: 1.15.x + go: 1.16.x branches: only: diff --git a/flate/deflate_test.go b/flate/deflate_test.go index 079040e8a2..65697b383b 100644 --- a/flate/deflate_test.go +++ b/flate/deflate_test.go @@ -609,6 +609,9 @@ func TestBestSpeed(t *testing.T) { } for i, tc := range testCases { + if testing.Short() && i > 5 { + t.Skip() + } for _, firstN := range []int{1, 65534, 65535, 65536, 65537, 131072} { tc[0] = firstN outer: diff --git a/flate/flate_test.go b/flate/flate_test.go index 52517d888c..8e2e5679f0 100644 --- a/flate/flate_test.go +++ b/flate/flate_test.go @@ -88,80 +88,85 @@ func TestRegressions(t *testing.T) { if err != nil { t.Fatal(err) } - for level := 0; level <= 9; level++ { - t.Run(fmt.Sprint(tt.Name+"-level", 1), func(t *testing.T) { + t.Run(tt.Name, func(t *testing.T) { + if testing.Short() && len(data1) > 10000 { + t.SkipNow() + } + for level := 0; level <= 9; level++ { + t.Run(fmt.Sprint(tt.Name+"-level", 1), func(t *testing.T) { + buf := new(bytes.Buffer) + fw, err := NewWriter(buf, level) + if err != nil { + t.Error(err) + } + n, err := fw.Write(data1) + if n != len(data1) { + t.Error("short write") + } + if err != nil { + t.Error(err) + } + err = fw.Close() + if err != nil { + t.Error(err) + } + fr1 := NewReader(buf) + data2, err := ioutil.ReadAll(fr1) + if err != nil { + t.Error(err) + } + if bytes.Compare(data1, data2) != 0 { + t.Error("not equal") + } + // Do it again... + buf.Reset() + fw.Reset(buf) + n, err = fw.Write(data1) + if n != len(data1) { + t.Error("short write") + } + if err != nil { + t.Error(err) + } + err = fw.Close() + if err != nil { + t.Error(err) + } + fr1 = flate.NewReader(buf) + data2, err = ioutil.ReadAll(fr1) + if err != nil { + t.Error(err) + } + if bytes.Compare(data1, data2) != 0 { + t.Error("not equal") + } + }) + } + t.Run(tt.Name+"stateless", func(t *testing.T) { + // Split into two and use history... buf := new(bytes.Buffer) - fw, err := NewWriter(buf, level) - if err != nil { - t.Error(err) - } - n, err := fw.Write(data1) - if n != len(data1) { - t.Error("short write") - } + err = StatelessDeflate(buf, data1[:len(data1)/2], false, nil) if err != nil { t.Error(err) } - err = fw.Close() + + // Use top half as dictionary... + dict := data1[:len(data1)/2] + err = StatelessDeflate(buf, data1[len(data1)/2:], true, dict) if err != nil { t.Error(err) } + t.Log(buf.Len()) fr1 := NewReader(buf) data2, err := ioutil.ReadAll(fr1) if err != nil { t.Error(err) } if bytes.Compare(data1, data2) != 0 { - t.Error("not equal") - } - // Do it again... - buf.Reset() - fw.Reset(buf) - n, err = fw.Write(data1) - if n != len(data1) { - t.Error("short write") - } - if err != nil { - t.Error(err) - } - err = fw.Close() - if err != nil { - t.Error(err) - } - fr1 = flate.NewReader(buf) - data2, err = ioutil.ReadAll(fr1) - if err != nil { - t.Error(err) - } - if bytes.Compare(data1, data2) != 0 { + fmt.Printf("want:%x\ngot: %x\n", data1, data2) t.Error("not equal") } }) - } - t.Run(tt.Name+"stateless", func(t *testing.T) { - // Split into two and use history... - buf := new(bytes.Buffer) - err = StatelessDeflate(buf, data1[:len(data1)/2], false, nil) - if err != nil { - t.Error(err) - } - - // Use top half as dictionary... - dict := data1[:len(data1)/2] - err = StatelessDeflate(buf, data1[len(data1)/2:], true, dict) - if err != nil { - t.Error(err) - } - t.Log(buf.Len()) - fr1 := NewReader(buf) - data2, err := ioutil.ReadAll(fr1) - if err != nil { - t.Error(err) - } - if bytes.Compare(data1, data2) != 0 { - fmt.Printf("want:%x\ngot: %x\n", data1, data2) - t.Error("not equal") - } }) } } diff --git a/flate/writer_test.go b/flate/writer_test.go index 46a064440d..a05af83212 100644 --- a/flate/writer_test.go +++ b/flate/writer_test.go @@ -36,6 +36,9 @@ func TestWriterRegression(t *testing.T) { } t.Run(tt.Name, func(t *testing.T) { + if testing.Short() && tt.FileInfo().Size() > 10000 { + t.SkipNow() + } r, err := tt.Open() if err != nil { t.Error(err) diff --git a/s2/encode_test.go b/s2/encode_test.go index fd668c86a3..0a3c0ccbdc 100644 --- a/s2/encode_test.go +++ b/s2/encode_test.go @@ -78,6 +78,9 @@ func TestEncoderRegression(t *testing.T) { } // Same as fuzz test... test := func(t *testing.T, data []byte) { + if testing.Short() && len(data) > 10000 { + t.SkipNow() + } for name, opts := range testOptions(t) { t.Run(name, func(t *testing.T) { var buf bytes.Buffer diff --git a/s2/s2_test.go b/s2/s2_test.go index 2fc5b1da36..c56d5bc921 100644 --- a/s2/s2_test.go +++ b/s2/s2_test.go @@ -1780,6 +1780,9 @@ func testFile(t *testing.T, i, repeat int) { t.Run(fmt.Sprint(i, "-", testFiles[i].label), func(t *testing.T) { bDir := filepath.FromSlash(*benchdataDir) data := readFile(t, filepath.Join(bDir, testFiles[i].filename)) + if testing.Short() && len(data) > 10000 { + t.SkipNow() + } oSize := len(data) for i := 0; i < repeat; i++ { data = append(data, data[:oSize]...) @@ -1839,6 +1842,9 @@ func TestDataRoundtrips(t *testing.T) { } t.Run("longblock", func(t *testing.T) { data := make([]byte, 1<<25) + if testing.Short() { + data = data[:1<<20] + } test(t, data) }) t.Run("4f9e1a0", func(t *testing.T) { diff --git a/zstd/dict_test.go b/zstd/dict_test.go index 70eb8863b7..433349c5d4 100644 --- a/zstd/dict_test.go +++ b/zstd/dict_test.go @@ -144,6 +144,9 @@ func TestEncoder_SmallDict(t *testing.T) { if err != nil { t.Fatal(err) } + if testing.Short() && len(decoded) > 1000 { + continue + } t.Run("encodeall-"+tt.Name, func(t *testing.T) { // Attempt to compress with all dicts @@ -347,10 +350,13 @@ func TestDecoder_MoreDicts(t *testing.T) { return } defer dec.Close() - for _, tt := range zr.File { + for i, tt := range zr.File { if !strings.HasSuffix(tt.Name, ".zst") { continue } + if testing.Short() && i > 50 { + continue + } t.Run("decodeall-"+tt.Name, func(t *testing.T) { r, err := tt.Open() if err != nil { diff --git a/zstd/encoder_test.go b/zstd/encoder_test.go index b475a2a380..e131753516 100644 --- a/zstd/encoder_test.go +++ b/zstd/encoder_test.go @@ -127,6 +127,9 @@ func TestEncoder_EncodeAllEncodeXML(t *testing.T) { if err != nil { t.Fatal(err) } + if testing.Short() { + in = in[:10000] + } for level := EncoderLevel(speedNotSet + 1); level < speedLast; level++ { t.Run(level.String(), func(t *testing.T) { @@ -336,7 +339,7 @@ func TestEncoder_EncodeAllPi(t *testing.T) { func TestWithEncoderPadding(t *testing.T) { n := 100 if testing.Short() { - n = 5 + n = 2 } rng := rand.New(rand.NewSource(0x1337)) d, err := NewReader(nil) @@ -471,6 +474,11 @@ func testEncoderRoundtrip(t *testing.T, file string, wantCRC []byte) { t.Fatal(err) } defer f.Close() + if stat, err := f.Stat(); testing.Short() && err == nil { + if stat.Size() > 10000 { + t.SkipNow() + } + } input := io.Reader(f) if strings.HasSuffix(file, ".zst") { dec, err := NewReader(f) @@ -562,6 +570,11 @@ func testEncoderRoundtripWriter(t *testing.T, file string, wantCRC []byte) { t.Fatal(err) } defer f.Close() + if stat, err := f.Stat(); testing.Short() && err == nil { + if stat.Size() > 10000 { + t.SkipNow() + } + } input := io.Reader(f) if strings.HasSuffix(file, ".zst") { dec, err := NewReader(f)