Skip to content

Commit 0a525a3

Browse files
kolyshkincagedmantis
authored andcommitted
[release-branch.go1.22] 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. For #68687 For #68663 Fixes #68811 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> (cherry picked from commit 84266e1) Reviewed-on: https://go-review.googlesource.com/c/go/+/605375 Reviewed-by: Carlos Amedee <carlos@golang.org>
1 parent cb4eee6 commit 0a525a3

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
@@ -1382,23 +1382,19 @@ func TestChtimes(t *testing.T) {
13821382
t.Parallel()
13831383

13841384
f := newFile("TestChtimes", t)
1385+
// This should be an empty file (see #68687, #68663).
13851386
defer Remove(f.Name())
1386-
1387-
f.Write([]byte("hello, world\n"))
13881387
f.Close()
13891388

13901389
testChtimes(t, f.Name())
13911390
}
13921391

13931392
func TestChtimesWithZeroTimes(t *testing.T) {
13941393
file := newFile("chtimes-with-zero", t)
1395-
_, err := file.Write([]byte("hello, world\n"))
1396-
if err != nil {
1397-
t.Fatalf("Write: %s", err)
1398-
}
1394+
// This should be an empty file (see #68687, #68663).
13991395
fName := file.Name()
14001396
defer Remove(file.Name())
1401-
err = file.Close()
1397+
err := file.Close()
14021398
if err != nil {
14031399
t.Errorf("%v", err)
14041400
}

0 commit comments

Comments
 (0)