test(watchdog): 状态文件先拨回上一轮的时间,Linux 粗粒度 mtime 下备用文件不再和它同刻

This commit is contained in:
Lemon-miaow committed 2026-09-29 02:28:50 +08:00
1 parent 20c4ae5567
commit 01cd69692f
1 file changed
+7
+7
View File
@@ -262,6 +262,13 @@ func TestSaveStateOr(t *testing.T) {
if got := NewestState(path, fallback); got != path {
t.Fatalf("no fallback yet: NewestState = %q, want the file", got)
}
// An earlier run wrote the file, minutes before this one. Linux stamps files
// from a coarse clock, so two writes a test makes back to back can share an
// mtime, and a tie reads the file.
earlier := time.Now().Add(-time.Hour)
if err := os.Chtimes(path, earlier, earlier); err != nil {
t.Fatal(err)
}
mailed := &State{Recipients: []string{"[email protected]"}}
run(mailed, Report{Findings: []Finding{finding("memory", Warning, 0)}}, t0)