Make a timed batch write on every tick (closes #192) #193

Merged
clawbot merged 1 commits from issue-192-timed-write-every-tick into next 2026-10-27 15:23:53 +01:00
Collaborator

Fixes #192.

Cause. The flush loop skipped a tick unless one interval had passed since the last write ended. The next tick came a little less than one interval after that. So the prefix handler wrote about every 2 seconds, and the AS and peer handlers about every 4.

Change.

  • Every tick of the timer writes.
  • A full batch's write restarts the timer as it begins, so the next timed write comes one interval after that write began.
  • A full batch still wakes the loop at once, and a waiting stop still goes first.
  • flushBatch no longer reports whether it wrote a batch. Only the old check read that.
  • TestFlushLoopWritesOnEveryTick runs flushLoop in a testing/synctest bubble, whose clock is fake. It fails on the old code.

Worth knowing. time.Sleep in the test only moves the bubble's fake clock. Ticker.Reset drops a tick already waiting in the channel, which the loop relies on; Go has guaranteed this since 1.23.

Judgement call: the brief said to record the time a write starts and compare it at each tick. Two ticks one interval apart can reach the loop a hair less than one interval apart, so that comparison would still skip some ticks. Restarting the timer needs no comparison.
Unverified: that tick timing claim is reasoning, not measured.
Not changed: TestPrefixHandlerWritesTheTableChangesEachSecond still waits on the real one-second timer, as before. It tests that timer.

Model: opus-5-5

Fixes https://git.eeqj.de/sneak/routewatch/issues/192. **Cause.** The flush loop skipped a tick unless one interval had passed since the last write ended. The next tick came a little less than one interval after that. So the prefix handler wrote about every 2 seconds, and the AS and peer handlers about every 4. **Change.** - Every tick of the timer writes. - A full batch's write restarts the timer as it begins, so the next timed write comes one interval after that write began. - A full batch still wakes the loop at once, and a waiting stop still goes first. - `flushBatch` no longer reports whether it wrote a batch. Only the old check read that. - `TestFlushLoopWritesOnEveryTick` runs `flushLoop` in a `testing/synctest` bubble, whose clock is fake. It fails on the old code. **Worth knowing.** `time.Sleep` in the test only moves the bubble's fake clock. `Ticker.Reset` drops a tick already waiting in the channel, which the loop relies on; Go has guaranteed this since 1.23. Judgement call: the brief said to record the time a write starts and compare it at each tick. Two ticks one interval apart can reach the loop a hair less than one interval apart, so that comparison would still skip some ticks. Restarting the timer needs no comparison. Unverified: that tick timing claim is reasoning, not measured. Not changed: `TestPrefixHandlerWritesTheTableChangesEachSecond` still waits on the real one-second timer, as before. It tests that timer. Model: opus-5-5
clawbot added the needs-review label 2026-10-27 15:06:43 +01:00
clawbot self-assigned this 2026-10-27 15:06:43 +01:00
clawbot added 1 commit 2026-10-27 15:06:44 +01:00
The prefix, AS and peer handlers skipped a timed write unless one
interval had passed since the last write ended. The next tick came a
little less than one interval after that, so every other tick was
skipped. Each tick now writes. A full batch's write restarts the timer,
so the next timed write comes one interval after that write began.
Comparing clock readings would not do: two ticks one interval apart can
read a hair under it. flushBatch no longer reports whether it wrote a
batch, since nothing reads that. A new test runs the loop on a fake
clock and fails on the old code.

Model: opus-5-5
Author
Collaborator

PASS: this meets the definition of done of #192 and is ready to merge into next.

Model: opus-5-5

PASS: this meets the definition of done of https://git.eeqj.de/sneak/routewatch/issues/192 and is ready to merge into `next`. Model: opus-5-5
clawbot merged commit 2c304a0022 into next 2026-10-27 15:23:53 +01:00
clawbot deleted branch issue-192-timed-write-every-tick 2026-10-27 15:23:54 +01:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/routewatch#193