1
0
mirror of https://github.com/golang/go synced 2024-11-23 15:20:03 -07:00

cmd/dist: run shards of test dir in parallel

Saves 15 seconds from all.bash on my laptop (3:20 -> 3:05).

Change-Id: Ic5dc3c7804e78b584789dd856a3dada94000a8e2
Reviewed-on: https://go-review.googlesource.com/18199
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Russ Cox 2015-12-21 20:42:40 -05:00
parent b6473ff132
commit d513ee774c

42
src/cmd/dist/test.go vendored
View File

@ -17,6 +17,7 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
) )
@ -195,6 +196,7 @@ func (t *tester) run() {
} }
dt := dt // dt used in background after this iteration dt := dt // dt used in background after this iteration
if err := dt.fn(&dt); err != nil { if err := dt.fn(&dt); err != nil {
t.runPending(dt) // in case that hasn't been done yet
t.failed = true t.failed = true
if t.keepGoing { if t.keepGoing {
log.Printf("Failed: %v", err) log.Printf("Failed: %v", err)
@ -788,8 +790,11 @@ func (t *tester) cgoTest(dt *distTest) error {
} }
// run pending test commands, in parallel, emitting headers as appropriate. // run pending test commands, in parallel, emitting headers as appropriate.
// When finished, emit header for dt, which is going to run after the // When finished, emit header for nextTest, which is going to run after the
// pending commands are done (and runPending returns). // pending commands are done (and runPending returns).
// A test should call runPending if it wants to make sure that it is not
// running in parallel with earlier tests, or if it has some other reason
// for needing the earlier tests to be done.
func (t *tester) runPending(nextTest *distTest) { func (t *tester) runPending(nextTest *distTest) {
worklist := t.worklist worklist := t.worklist
t.worklist = nil t.worklist = nil
@ -961,20 +966,35 @@ func (t *tester) raceTest(dt *distTest) error {
return nil return nil
} }
var runtest struct {
sync.Once
exe string
err error
}
func (t *tester) testDirTest(dt *distTest, shard, shards int) error { func (t *tester) testDirTest(dt *distTest, shard, shards int) error {
t.runPending(dt) runtest.Do(func() {
const runExe = "runtest.exe" // named exe for Windows, but harmless elsewhere const exe = "runtest.exe" // named exe for Windows, but harmless elsewhere
cmd := t.dirCmd("test", "go", "build", "-o", runExe, "run.go") cmd := t.dirCmd("test", "go", "build", "-o", exe, "run.go")
cmd.Env = mergeEnvLists([]string{"GOOS=" + t.gohostos, "GOARCH=" + t.gohostarch, "GOMAXPROCS="}, os.Environ()) cmd.Env = mergeEnvLists([]string{"GOOS=" + t.gohostos, "GOARCH=" + t.gohostarch, "GOMAXPROCS="}, os.Environ())
if err := cmd.Run(); err != nil { runtest.exe = filepath.Join(cmd.Dir, exe)
return err if err := cmd.Run(); err != nil {
runtest.err = err
return
}
xatexit(func() {
os.Remove(runtest.exe)
})
})
if runtest.err != nil {
return runtest.err
} }
absExe := filepath.Join(cmd.Dir, runExe)
defer os.Remove(absExe) t.addCmd(dt, "test", runtest.exe,
return t.dirCmd("test", absExe,
fmt.Sprintf("--shard=%d", shard), fmt.Sprintf("--shard=%d", shard),
fmt.Sprintf("--shards=%d", shards), fmt.Sprintf("--shards=%d", shards),
).Run() )
return nil
} }
func (t *tester) shootoutTests() []string { func (t *tester) shootoutTests() []string {