tg.setenv("GOPATH", tg.tempdir)
tg.setenv("GOCACHE", filepath.Join(tg.tempdir, "cache"))
- tg.run("test", "-x", "errors")
+ // timeout here should not affect result being cached
+ // or being retrieved later.
+ tg.run("test", "-x", "-timeout=10s", "errors")
tg.grepStderr(`[\\/]compile|gccgo`, "did not run compiler")
tg.grepStderr(`[\\/]link|gccgo`, "did not run linker")
tg.grepStderr(`errors\.test`, "did not run test")
tg.grepStderrNot(`errors\.test`, "incorrectly ran test")
tg.grepStderrNot("DO NOT USE", "poisoned action status leaked")
+ // Even very low timeouts do not disqualify cached entries.
+ tg.run("test", "-timeout=1ns", "-x", "errors")
+ tg.grepStderrNot(`errors\.test`, "incorrectly ran test")
+
// The -p=1 in the commands below just makes the -x output easier to read.
t.Log("\n\nINITIAL\n\n")
binary again. In the summary line, go test prints '(cached)' in place of
the elapsed time. To disable test caching, use any test flag or argument
other than the cacheable flags. The idiomatic way to disable test caching
-explicitly is to use -count=1.
+explicitly is to use -count=1. A cached result is treated as executing in
+no time at all, so a successful package test result will be cached and reused
+regardless of -timeout setting.
` + strings.TrimSpace(testFlag1) + ` See 'go help testflag' for details.
return false
}
+ var cacheArgs []string
for _, arg := range testArgs {
i := strings.Index(arg, "=")
if i < 0 || !strings.HasPrefix(arg, "-test.") {
// These are cacheable.
// Note that this list is documented above,
// so if you add to this list, update the docs too.
+ cacheArgs = append(cacheArgs, arg)
+
+ case "-test.timeout":
+ // Special case: this is cacheable but ignored during the hash.
+ // Do not add to cacheArgs.
+
default:
// nothing else is cacheable
c.disableCache = true
}
h := cache.NewHash("testResult")
- fmt.Fprintf(h, "test binary %s args %q execcmd %q", id, testArgs, work.ExecCmd)
+ fmt.Fprintf(h, "test binary %s args %q execcmd %q", id, cacheArgs, work.ExecCmd)
// TODO(rsc): How to handle other test dependencies like environment variables or input files?
// We could potentially add new API like testing.UsedEnv(envName string)
// or testing.UsedFile(inputFile string) to let tests declare what external inputs