Skip to content

Commit

Permalink
internal/mod/zip: skip SizeLimit tests with -race
Browse files Browse the repository at this point in the history
These tests create very large zip files on purpose,
which is very slow under the race detector due to compress/flate.

The tests and tested API have no concurrency at all,
so the data race detector doesn't add anything useful.
The slowness simply makes our CI's `go test -race ./...` too slow.

Skip the tests when the data race detector is enabled.
Since the upstream Go proposal for runtime/race.Enabled was rejected,
add a similar constant to our internal/cuetest package.

`go test -race ./internal/mod/zip` drops from ~40s to ~1s on my laptop.

Note that we already skip these tests in `go test -short` mode,
but we don't want CI to use `go test -race -short ./...`,
as the data race detector is still useful on other non-short tests.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I44f707c8220af8bb943f5c3e162ef948a78a34c0
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1170024
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mvdan committed Sep 27, 2023
1 parent 665d19a commit 91d9766
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
19 changes: 19 additions & 0 deletions internal/cuetest/norace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 The CUE Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !race

package cuetest

const RaceEnabled = false
19 changes: 19 additions & 0 deletions internal/cuetest/race.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 The CUE Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build race

package cuetest

const RaceEnabled = true
7 changes: 4 additions & 3 deletions internal/mod/zip/zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/google/go-cmp/cmp"

"cuelang.org/go/internal/cuetest"
"cuelang.org/go/internal/mod/module"
modzip "cuelang.org/go/internal/mod/zip"
"golang.org/x/mod/sumdb/dirhash"
Expand Down Expand Up @@ -720,7 +721,7 @@ var sizeLimitTests = [...]sizeLimitTest{
var sizeLimitVersion = module.MustNewVersion("example.com/large@v1", "v1.0.0")

func TestCreateSizeLimits(t *testing.T) {
if testing.Short() {
if testing.Short() || cuetest.RaceEnabled {
t.Skip("creating large files takes time")
}
t.Parallel()
Expand Down Expand Up @@ -782,7 +783,7 @@ func TestCreateSizeLimits(t *testing.T) {
}

func TestUnzipSizeLimits(t *testing.T) {
if testing.Short() {
if testing.Short() || cuetest.RaceEnabled {
t.Skip("creating large files takes time")
}
t.Parallel()
Expand Down Expand Up @@ -849,7 +850,7 @@ func TestUnzipSizeLimits(t *testing.T) {
}

func TestUnzipSizeLimitsSpecial(t *testing.T) {
if testing.Short() {
if testing.Short() || cuetest.RaceEnabled {
t.Skip("skipping test; creating large files takes time")
}

Expand Down

0 comments on commit 91d9766

Please sign in to comment.