]> Cypherpunks repositories - gostls13.git/commitdiff
testing: error if -parallel is given N<1
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 9 Aug 2017 07:56:08 +0000 (16:56 +0900)
committerIan Lance Taylor <iant@golang.org>
Fri, 25 Aug 2017 22:47:57 +0000 (22:47 +0000)
Otherwise, if there are any parallel tests, it will hang and panic with
"all goroutines are asleep - deadlock!".

Do not use flag.Uint to handle the error for us because we also want to
error on N==0, and because it would make setting the default to
GOMAXPROCS(0) more difficult, since it's an int.

Check for it right after flag.Parse, and mimic flag errors by printing
the usage and returning exit code 2.

Fixes #20542.

Change-Id: I0c9d4587f83d406a8f5e42ed74e40be46d639ffb
Reviewed-on: https://go-review.googlesource.com/54150
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go
src/testing/testing.go

index d7206112162ef35e28463d1bfd97260ac7af7bb4..87810ad6cb53bce6fdafa656aed228ae0d5cb8db 100644 (file)
@@ -4487,3 +4487,14 @@ func TestExecBuildX(t *testing.T) {
                t.Fatalf("got %q; want %q", out, "hello")
        }
 }
+
+func TestParallelNumber(t *testing.T) {
+       for _, n := range [...]string{"-1", "0"} {
+               t.Run(n, func(t *testing.T) {
+                       tg := testgo(t)
+                       defer tg.cleanup()
+                       tg.runFail("test", "-parallel", n, "testdata/standalone_parallel_sub_test.go")
+                       tg.grepBoth("-parallel can only be given", "go test -parallel with N<1 did not error")
+               })
+       }
+}
index 53283796f87886e649c13b470df6f1c837cda716..8b4bfc31a82e51c15a02fc111e92770422f01843 100644 (file)
@@ -913,6 +913,12 @@ func (m *M) Run() int {
                flag.Parse()
        }
 
+       if *parallel < 1 {
+               fmt.Fprintln(os.Stderr, "testing: -parallel can only be given a positive integer")
+               flag.Usage()
+               return 2
+       }
+
        if len(*matchList) != 0 {
                listTests(m.deps.MatchString, m.tests, m.benchmarks, m.examples)
                return 0