Unverified Commit 01cd6969 authored by Lemon-miaow's avatar Lemon-miaow
Browse files

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

parent 20c4ae55
Loading
Loading
Loading
Loading
+7 −0
Changes for internal/watchdog/watchdog_test.go: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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)