test(watchdog): 状态文件先拨回上一轮的时间,Linux 粗粒度 mtime 下备用文件不再和它同刻
This commit is contained in:
1 file changed
+7
@@ -262,6 +262,13 @@ func TestSaveStateOr(t *testing.T) {
|
|||||||
if got := NewestState(path, fallback); got != path {
|
if got := NewestState(path, fallback); got != path {
|
||||||
t.Fatalf("no fallback yet: NewestState = %q, want the file", got)
|
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]"}}
|
mailed := &State{Recipients: []string{"[email protected]"}}
|
||||||
run(mailed, Report{Findings: []Finding{finding("memory", Warning, 0)}}, t0)
|
run(mailed, Report{Findings: []Finding{finding("memory", Warning, 0)}}, t0)
|
||||||
|
|||||||
Reference in new issue
Block a user