Skip to content

Commit 84266e1

Browse files
kolyshkingopherbot
authored andcommitted
os: fix Chtimes test flakes
It appears that some builders (notably, linux-arm) have some additional security software installed, which apparently reads the files created by tests. As a result, test file atime is changed, making the test fail like these: === RUN TestChtimesOmit ... os_test.go:1475: atime mismatch, got: "2024-07-30 18:42:03.450932494 +0000 UTC", want: "2024-07-30 18:42:02.450932494 +0000 UTC" === RUN TestChtimes ... os_test.go:1539: AccessTime didn't go backwards; was=2024-07-31 20:45:53.390326147 +0000 UTC, after=2024-07-31 20:45:53.394326118 +0000 UTC According to inode(7), atime is changed when more than 0 bytes are read from the file. So, one possible solution to these flakes is to make the test files empty, so no one can read more than 0 bytes from them. Fixes #68687 Fixes #68663 Change-Id: Ib9234567883ef7b16ff8811e3360cd26c2d6bdab Reviewed-on: https://go-review.googlesource.com/c/go/+/604315 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Kirill Kolyshkin <kolyshkin@gmail.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
1 parent ed31d64 commit 84266e1

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

‎src/os/os_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,8 +1375,7 @@ func TestChtimes(t *testing.T) {
13751375
t.Parallel()
13761376

13771377
f := newFile(t)
1378-
1379-
f.Write([]byte("hello, world\n"))
1378+
// This should be an empty file (see #68687, #68663).
13801379
f.Close()
13811380

13821381
testChtimes(t, f.Name())
@@ -1394,12 +1393,9 @@ func TestChtimesOmit(t *testing.T) {
13941393
func testChtimesOmit(t *testing.T, omitAt, omitMt bool) {
13951394
t.Logf("omit atime: %v, mtime: %v", omitAt, omitMt)
13961395
file := newFile(t)
1397-
_, err := file.Write([]byte("hello, world\n"))
1398-
if err != nil {
1399-
t.Fatal(err)
1400-
}
1396+
// This should be an empty file (see #68687, #68663).
14011397
name := file.Name()
1402-
err = file.Close()
1398+
err := file.Close()
14031399
if err != nil {
14041400
t.Error(err)
14051401
}

0 commit comments

Comments
 (0)