Skip to content

Commit cc75ec0

Browse files
committed
cmd/go: add local module proxy to make tests faster
Because "go get" with modules enabled allows use of a proxy, we can run a proxy in the test and serve modules from local files, which makes the tests not depend on remote network servers and run significantly faster, speeding development. The proxy serves modules from the testdata/mod directory, which holds one txtar archive per module. See testdata/mod/README. Reduces time for 'go test -run=^TestMod' from 115s to 11.9s. Still longer than I would like but significantly better. Change-Id: I1b8367b208a02549a44e91e4ea5c5fb9003123ae Reviewed-on: https://go-review.googlesource.com/123361 Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 91f8741 commit cc75ec0

File tree

75 files changed

+4128
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4128
-347
lines changed

vendor/cmd/go/go_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"bytes"
99
"debug/elf"
1010
"debug/macho"
11+
"flag"
1112
"fmt"
1213
"go/format"
1314
"internal/race"
@@ -112,6 +113,12 @@ func TestMain(m *testing.M) {
112113
}
113114
os.Unsetenv("GOROOT_FINAL")
114115

116+
flag.Parse()
117+
if *proxyAddr != "" {
118+
StartProxy()
119+
select {}
120+
}
121+
115122
if canRun {
116123
args := []string{"build", "-tags", "testgo", "-o", "testgo" + exeSuffix, "../../.."}
117124
if race.Enabled {
@@ -417,7 +424,8 @@ func (tg *testgoData) doRun(args []string) error {
417424
func (tg *testgoData) run(args ...string) {
418425
tg.t.Helper()
419426
if status := tg.doRun(args); status != nil {
420-
tg.t.Logf("go %v failed unexpectedly: %v", args, status)
427+
wd, _ := os.Getwd()
428+
tg.t.Logf("go %v failed unexpectedly in %s: %v", args, wd, status)
421429
tg.t.FailNow()
422430
}
423431
}
@@ -760,16 +768,28 @@ func (tg *testgoData) wantNotStale(pkg, reason, msg string) {
760768
}
761769
}
762770

771+
// If -testwork is specified, the test prints the name of the temp directory
772+
// and does not remove it when done, so that a programmer can
773+
// poke at the test file tree afterward.
774+
var testWork = flag.Bool("testwork", false, "")
775+
763776
// cleanup cleans up a test that runs testgo.
764777
func (tg *testgoData) cleanup() {
765778
tg.t.Helper()
766779
if tg.wd != "" {
780+
wd, _ := os.Getwd()
781+
tg.t.Logf("ended in %s", wd)
782+
767783
if err := os.Chdir(tg.wd); err != nil {
768784
// We are unlikely to be able to continue.
769785
fmt.Fprintln(os.Stderr, "could not restore working directory, crashing:", err)
770786
os.Exit(2)
771787
}
772788
}
789+
if *testWork {
790+
tg.t.Logf("TESTWORK=%s\n", tg.path("."))
791+
return
792+
}
773793
for _, path := range tg.temps {
774794
tg.check(removeAll(path))
775795
}

0 commit comments

Comments
 (0)