]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add a 'sleep' command for script tests
authorBryan C. Mills <bcmills@google.com>
Thu, 30 Jun 2022 17:30:48 +0000 (13:30 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 30 Jun 2022 18:10:53 +0000 (18:10 +0000)
Due to mtime skew we don't index mutable packages with an mtime
younger than 2 seconds. In order to test indexed packages reliably, we
want to be able to sleep long enough for the files in the package to be cached.

(As an alternative we could instead use os.Chtimes to fake old enough
timestamps, but sleeping keeps the tests more realistic.)

For #53586.

Change-Id: I1873f47c55a72d928451593b8c989f0092a557db
Reviewed-on: https://go-review.googlesource.com/c/go/+/415474
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/script_test.go
src/cmd/go/testdata/script/README

index 3ad0608725e91066a8e36050cefc992db09dbc01..5e82929f19a5dd4bfe86110f44d8f92ddec551cf 100644 (file)
@@ -521,6 +521,7 @@ var scriptCmds = map[string]func(*testScript, simpleStatus, []string){
        "mv":      (*testScript).cmdMv,
        "rm":      (*testScript).cmdRm,
        "skip":    (*testScript).cmdSkip,
+       "sleep":   (*testScript).cmdSleep,
        "stale":   (*testScript).cmdStale,
        "stderr":  (*testScript).cmdStderr,
        "stdout":  (*testScript).cmdStdout,
@@ -921,6 +922,21 @@ func (ts *testScript) cmdSkip(want simpleStatus, args []string) {
        ts.t.Skip()
 }
 
+// sleep sleeps for the given duration
+func (ts *testScript) cmdSleep(want simpleStatus, args []string) {
+       if len(args) != 1 {
+               ts.fatalf("usage: sleep duration")
+       }
+       d, err := time.ParseDuration(args[0])
+       if err != nil {
+               ts.fatalf("sleep: %v", err)
+       }
+       if want != success {
+               ts.fatalf("unsupported: %v sleep", want)
+       }
+       time.Sleep(d)
+}
+
 // stale checks that the named build targets are stale.
 func (ts *testScript) cmdStale(want simpleStatus, args []string) {
        if len(args) == 0 {
index 85e575d56eed39d4aef1891b120fbdd07cb65d8e..c575bff1a517fc3d9db781dbd161633f267ba6a1 100644 (file)
@@ -176,6 +176,11 @@ The commands are:
 - skip [message]
   Mark the test skipped, including the message if given.
 
+- sleep duration
+  Sleep for the given duration (a time.Duration string).
+  (Tests should generally poll instead of sleeping, but sleeping may sometimes
+  be necessary, for example, to ensure that modified files have unique mtimes.)
+
 - [!] stale path...
   The packages named by the path arguments must (or must not)
   be reported as "stale" by the go command.