Skip to content

Commit c55a50e

Browse files
author
Bryan C. Mills
committed
cmd/go: invalidate cached test results when the -timeout flag changes
Fixes #36134 Change-Id: Icc5e1269696db778ba5c1e6bebed9969b8841c81 Reviewed-on: https://go-review.googlesource.com/c/go/+/220365 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent 68fea52 commit c55a50e

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

doc/go1.15.html

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ <h3 id="go-command">Go command</h3>
4747
TODO
4848
</p>
4949

50+
<h4 id="go-test"><code>go</code> <code>test</code></h4>
51+
52+
<p><!-- https://golang.org/issue/36134 -->
53+
Changing the <code>-timeout</code> flag now invalidates cached test results. A
54+
cached result for a test run with a long timeout will no longer count as
55+
passing when <code>go</code> <code>test</code> is re-invoked with a short one.
56+
</p>
57+
5058
<h4 id="go-flag-parsing">Flag parsing</h4>
5159

5260
<p><!-- https://golang.org/cl/211358 -->

src/cmd/go/go_test.go

-24
Original file line numberDiff line numberDiff line change
@@ -2431,30 +2431,6 @@ func TestTestCache(t *testing.T) {
24312431
tg.setenv("GOPATH", tg.tempdir)
24322432
tg.setenv("GOCACHE", tg.path("cache"))
24332433

2434-
if runtime.Compiler != "gccgo" {
2435-
// timeout here should not affect result being cached
2436-
// or being retrieved later.
2437-
tg.run("test", "-x", "-timeout=10s", "errors")
2438-
tg.grepStderr(`[\\/]compile|gccgo`, "did not run compiler")
2439-
tg.grepStderr(`[\\/]link|gccgo`, "did not run linker")
2440-
tg.grepStderr(`errors\.test`, "did not run test")
2441-
2442-
tg.run("test", "-x", "errors")
2443-
tg.grepStdout(`ok \terrors\t\(cached\)`, "did not report cached result")
2444-
tg.grepStderrNot(`[\\/]compile|gccgo`, "incorrectly ran compiler")
2445-
tg.grepStderrNot(`[\\/]link|gccgo`, "incorrectly ran linker")
2446-
tg.grepStderrNot(`errors\.test`, "incorrectly ran test")
2447-
tg.grepStderrNot("DO NOT USE", "poisoned action status leaked")
2448-
2449-
// Even very low timeouts do not disqualify cached entries.
2450-
tg.run("test", "-timeout=1ns", "-x", "errors")
2451-
tg.grepStderrNot(`errors\.test`, "incorrectly ran test")
2452-
2453-
tg.run("clean", "-testcache")
2454-
tg.run("test", "-x", "errors")
2455-
tg.grepStderr(`errors\.test`, "did not run test")
2456-
}
2457-
24582434
// The -p=1 in the commands below just makes the -x output easier to read.
24592435

24602436
t.Log("\n\nINITIAL\n\n")

src/cmd/go/internal/test/test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -1291,16 +1291,13 @@ func (c *runCache) tryCacheWithID(b *work.Builder, a *work.Action, id string) bo
12911291
"-test.parallel",
12921292
"-test.run",
12931293
"-test.short",
1294+
"-test.timeout",
12941295
"-test.v":
12951296
// These are cacheable.
12961297
// Note that this list is documented above,
12971298
// so if you add to this list, update the docs too.
12981299
cacheArgs = append(cacheArgs, arg)
12991300

1300-
case "-test.timeout":
1301-
// Special case: this is cacheable but ignored during the hash.
1302-
// Do not add to cacheArgs.
1303-
13041301
default:
13051302
// nothing else is cacheable
13061303
if cache.DebugTest {

src/cmd/go/testdata/script/test_cache_inputs.txt

+21
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ go test testcache -run=TestLookupEnv
2929
go test testcache -run=TestLookupEnv
3030
stdout '\(cached\)'
3131

32+
# Changes in arguments forwarded to the test should invalidate cached test
33+
# results.
34+
go test testcache -run=TestOSArgs -v hello
35+
! stdout '\(cached\)'
36+
stdout 'hello'
37+
go test testcache -run=TestOSArgs -v goodbye
38+
! stdout '\(cached\)'
39+
stdout 'goodbye'
40+
41+
# golang.org/issue/36134: that includes the `-timeout` argument.
42+
go test testcache -run=TestOSArgs -timeout=20m -v
43+
! stdout '\(cached\)'
44+
stdout '-test\.timeout[= ]20m'
45+
go test testcache -run=TestOSArgs -timeout=5s -v
46+
! stdout '\(cached\)'
47+
stdout '-test\.timeout[= ]5s'
48+
3249
# If the test stats a file, changes to the file should invalidate the cache.
3350
go test testcache -run=FileSize
3451
go test testcache -run=FileSize
@@ -207,6 +224,10 @@ func TestExternalFile(t *testing.T) {
207224
t.Fatal(err)
208225
}
209226
}
227+
228+
func TestOSArgs(t *testing.T) {
229+
t.Log(os.Args)
230+
}
210231
-- mkold.go --
211232
package main
212233

0 commit comments

Comments
 (0)