]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: avoid race on test environment
authorIan Lance Taylor <iant@golang.org>
Tue, 16 Feb 2016 15:13:10 +0000 (07:13 -0800)
committerIan Lance Taylor <iant@golang.org>
Tue, 16 Feb 2016 22:02:56 +0000 (22:02 +0000)
Fixes #14337.

Change-Id: I58aef7e08d936b0712da577dd1ce5c9ed5d8bfd2
Reviewed-on: https://go-review.googlesource.com/19513
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/dist/test.go
src/cmd/go/go_test.go
src/cmd/go/main.go

index 156b86810947b8e02bfb381f28742a5de389faff..36c829d1b93c1ca9742646b3438a6372db347caa 100644 (file)
@@ -947,6 +947,11 @@ func (t *tester) raceTest(dt *distTest) error {
        t.addCmd(dt, "src", "go", "test", "-race", "-i", "runtime/race", "flag", "os/exec")
        t.addCmd(dt, "src", "go", "test", "-race", "-run=Output", "runtime/race")
        t.addCmd(dt, "src", "go", "test", "-race", "-short", "-run=TestParse|TestEcho", "flag", "os/exec")
+       // We don't want the following line, because it
+       // slows down all.bash (by 10 seconds on my laptop).
+       // The race builder should catch any error here, but doesn't.
+       // TODO(iant): Figure out how to catch this.
+       // t.addCmd(dt, "src", "go", "test", "-race", "-run=TestParallelTest", "cmd/go")
        if t.cgoEnabled {
                env := mergeEnvLists([]string{"GOTRACEBACK=2"}, os.Environ())
                cmd := t.addCmd(dt, "misc/cgo/test", "go", "test", "-race", "-short")
index c60971efed3f5ba2b74aa9747a9ac9164a72a562..39e0f3e56d58b25a6dc4365bf41650fb47e4a70d 100644 (file)
@@ -10,6 +10,7 @@ import (
        "fmt"
        "go/build"
        "go/format"
+       "internal/race"
        "internal/testenv"
        "io"
        "io/ioutil"
@@ -69,7 +70,11 @@ func TestMain(m *testing.M) {
        flag.Parse()
 
        if canRun {
-               out, err := exec.Command("go", "build", "-tags", "testgo", "-o", "testgo"+exeSuffix).CombinedOutput()
+               args := []string{"build", "-tags", "testgo", "-o", "testgo" + exeSuffix}
+               if race.Enabled {
+                       args = append(args, "-race")
+               }
+               out, err := exec.Command("go", args...).CombinedOutput()
                if err != nil {
                        fmt.Fprintf(os.Stderr, "building testgo failed: %v\n%s", err, out)
                        os.Exit(2)
@@ -2735,3 +2740,22 @@ func TestIssue13655(t *testing.T) {
                tg.grepStdout("runtime/internal/sys", "did not find required dependency of "+pkg+" on runtime/internal/sys")
        }
 }
+
+// For issue 14337.
+func TestParallelTest(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.makeTempdir()
+       const testSrc = `package package_test
+               import (
+                       "testing"
+               )
+               func TestTest(t *testing.T) {
+               }`
+       tg.tempFile("src/p1/p1_test.go", strings.Replace(testSrc, "package_test", "p1_test", 1))
+       tg.tempFile("src/p2/p2_test.go", strings.Replace(testSrc, "package_test", "p2_test", 1))
+       tg.tempFile("src/p3/p3_test.go", strings.Replace(testSrc, "package_test", "p3_test", 1))
+       tg.tempFile("src/p4/p4_test.go", strings.Replace(testSrc, "package_test", "p4_test", 1))
+       tg.setenv("GOPATH", tg.path("."))
+       tg.run("test", "-p=4", "p1", "p2", "p3", "p4")
+}
index d384594722511028a25ea87d21279a35c72e7468..f9b979da7fba69a500a6db8d5c836c156485dcee 100644 (file)
@@ -454,7 +454,9 @@ func envForDir(dir string, base []string) []string {
 
 // mergeEnvLists merges the two environment lists such that
 // variables with the same name in "in" replace those in "out".
+// This always returns a newly allocated slice.
 func mergeEnvLists(in, out []string) []string {
+       out = append([]string(nil), out...)
 NextVar:
        for _, inkv := range in {
                k := strings.SplitAfterN(inkv, "=", 2)[0]