Pass the state-file flush to a subscription in its options

A subscription flushed its state file through a package variable, which
the ntfy tests replaced with a no-op in their TestMain. Tests in other
packages could not reach it, so the daemon's own tests still flushed
for real.

Options.Sync now takes the flush; nil means (*os.File).Sync, as before.
The ntfy tests pass a no-op through their options and to saveState.
Behaviour is unchanged.

docs/plans/ntfy.md names the option, and its line references follow the
code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-12-01 12:08:36 -06:00
1 parent c548833656
commit 62e5ec9c66
9 files changed
+49 -49

No files matched your search

+5 -5
View File
@@ -127,7 +127,7 @@ func TestBacklogUsesTheServerClock(t *testing.T) {
serverNow := func() int64 { return time.Now().Add(f.skew).Unix() }
// The subscription last ran ten hours ago by the server's clock.
if err := saveState(o.StateFile, state{Cursor: serverNow() - 10*3600}); err != nil {
if err := saveState(o.StateFile, state{Cursor: serverNow() - 10*3600}, skipSync); err != nil {
t.Fatal(err)
}
old := f.publish(Message{Title: "five hours ago", Time: serverNow() - 5*3600})
@@ -164,7 +164,7 @@ func TestBacklogFollowsTheStreamClock(t *testing.T) {
f.skew, f.authFails, f.noDate = tt.skew, true, tt.noDate
o := testOptions(f, t.TempDir())
serverNow := func() int64 { return time.Now().Add(f.skew).Unix() }
if err := saveState(o.StateFile, state{Cursor: serverNow() - 2*3600}); err != nil {
if err := saveState(o.StateFile, state{Cursor: serverNow() - 2*3600}, skipSync); err != nil {
t.Fatal(err)
}
old := f.publish(Message{Title: "ninety minutes ago", Time: serverNow() - 5400})
@@ -235,7 +235,7 @@ func TestBacklogIgnoresAnEarlierClock(t *testing.T) {
f := newFakeServer()
f.authSkew = tt.authSkew
o := testOptions(f, t.TempDir())
if err := saveState(o.StateFile, state{Cursor: time.Now().Unix() - 2*3600}); err != nil {
if err := saveState(o.StateFile, state{Cursor: time.Now().Unix() - 2*3600}, skipSync); err != nil {
t.Fatal(err)
}
old := f.publish(Message{Title: "ninety minutes ago", Time: time.Now().Unix() - 5400})
@@ -286,7 +286,7 @@ func TestBacklogPrefersTheOpenEvent(t *testing.T) {
f := newFakeServer()
f.dateSkew = tt.dateSkew
o := testOptions(f, t.TempDir())
if err := saveState(o.StateFile, state{Cursor: time.Now().Unix() - 2*3600}); err != nil {
if err := saveState(o.StateFile, state{Cursor: time.Now().Unix() - 2*3600}, skipSync); err != nil {
t.Fatal(err)
}
old := f.publish(Message{Title: "ninety minutes ago", Time: time.Now().Unix() - 5400})
@@ -327,7 +327,7 @@ func TestBacklogFromTheDate(t *testing.T) {
f.skew, f.openNoTime = 10*time.Hour, true
o := testOptions(f, t.TempDir())
serverNow := func() int64 { return time.Now().Add(f.skew).Unix() }
if err := saveState(o.StateFile, state{Cursor: serverNow() - 10*3600}); err != nil {
if err := saveState(o.StateFile, state{Cursor: serverNow() - 10*3600}, skipSync); err != nil {
t.Fatal(err)
}
old := f.publish(Message{Title: "five hours ago", Time: serverNow() - 5*3600})