Skip to content

Commit b004dd6

Browse files
committed
internal/mod/zip: make all tests parallel
I'm not sure why x/mod/zip only makes the sub-tests parallel. Two of these tests deal with very large zip files, but they don't create those large files in in-memory buffers; the Create test writes to io.Discard, and Unzip uses temporary files. Moreover, their subtests were already parallel, so we were already creating multiple such large files at once anyway. This helps slightly with `go test`, dropping from 2.9s to 1.6s while CPU usage increases from 150% to 280% on my laptop. The real difference is with `go test -race`, which we use in CI: I see a drop from 80s to 43s, again using multiple CPUs better. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I92cd8828ae2b11a7b83568c6145e020e3b54d754 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1170018 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent 6c51cf0 commit b004dd6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

internal/mod/zip/zip_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ func formatCheckedFiles(cf modzip.CheckedFiles) string {
202202
}
203203

204204
func TestCheckFilesWithDirWithTrailingSlash(t *testing.T) {
205+
t.Parallel()
205206
// When checking a zip file,
206207
files := []fakeFile{{
207208
name: "cue.mod/",
@@ -221,6 +222,7 @@ func TestCheckFilesWithDirWithTrailingSlash(t *testing.T) {
221222
// focuses on how multiple errors and omissions are reported, rather than trying
222223
// to cover every case.
223224
func TestCheckFiles(t *testing.T) {
225+
t.Parallel()
224226
testPaths, err := filepath.Glob(filepath.FromSlash("testdata/check_files/*.txt"))
225227
if err != nil {
226228
t.Fatal(err)
@@ -274,6 +276,7 @@ func TestCheckFiles(t *testing.T) {
274276
// test focuses on how multiple errors and omissions are reported, rather than
275277
// trying to cover every case.
276278
func TestCheckDir(t *testing.T) {
279+
t.Parallel()
277280
testPaths, err := filepath.Glob(filepath.FromSlash("testdata/check_dir/*.txt"))
278281
if err != nil {
279282
t.Fatal(err)
@@ -324,6 +327,7 @@ func TestCheckDir(t *testing.T) {
324327
// covered by TestUnzip, so this test focuses on how multiple errors are
325328
// reported, rather than trying to cover every case.
326329
func TestCheckZip(t *testing.T) {
330+
t.Parallel()
327331
testPaths, err := filepath.Glob(filepath.FromSlash("testdata/check_zip/*.txt"))
328332
if err != nil {
329333
t.Fatal(err)
@@ -373,6 +377,7 @@ func TestCheckZip(t *testing.T) {
373377
}
374378

375379
func TestCreate(t *testing.T) {
380+
t.Parallel()
376381
testDir := filepath.FromSlash("testdata/create")
377382
testInfos, err := os.ReadDir(testDir)
378383
if err != nil {
@@ -458,6 +463,7 @@ func shouldExclude(f *zip.File) bool {
458463
}
459464

460465
func TestCreateFromDir(t *testing.T) {
466+
t.Parallel()
461467
testDir := filepath.FromSlash("testdata/create_from_dir")
462468
testInfos, err := os.ReadDir(testDir)
463469
if err != nil {
@@ -513,6 +519,7 @@ func TestCreateFromDir(t *testing.T) {
513519
}
514520

515521
func TestCreateFromDirSpecial(t *testing.T) {
522+
t.Parallel()
516523
for _, test := range []struct {
517524
desc string
518525
setup func(t *testing.T, tmpDir string) string
@@ -589,6 +596,7 @@ func TestCreateFromDirSpecial(t *testing.T) {
589596
}
590597

591598
func TestUnzip(t *testing.T) {
599+
t.Parallel()
592600
testDir := filepath.FromSlash("testdata/unzip")
593601
testInfos, err := os.ReadDir(testDir)
594602
if err != nil {
@@ -714,6 +722,7 @@ func TestCreateSizeLimits(t *testing.T) {
714722
if testing.Short() {
715723
t.Skip("creating large files takes time")
716724
}
725+
t.Parallel()
717726
tests := append(sizeLimitTests[:], sizeLimitTest{
718727
// negative file size may happen when size is represented as uint64
719728
// but is cast to int64, as is the case in zip files.
@@ -775,6 +784,7 @@ func TestUnzipSizeLimits(t *testing.T) {
775784
if testing.Short() {
776785
t.Skip("creating large files takes time")
777786
}
787+
t.Parallel()
778788
for _, test := range sizeLimitTests {
779789
test := test
780790
t.Run(test.desc, func(t *testing.T) {
@@ -842,6 +852,7 @@ func TestUnzipSizeLimitsSpecial(t *testing.T) {
842852
t.Skip("skipping test; creating large files takes time")
843853
}
844854

855+
t.Parallel()
845856
for _, test := range []struct {
846857
desc string
847858
wantErr string

0 commit comments

Comments
 (0)