carlos / platform Public

ops: hibernate-verify publishes on a clock; no_record holds (#898)

Fix round 1 for Task 5. Periodic publication no longer waits for a host
to finish: a ticker every PublishEvery publishes a mutex-guarded copy
of the run's verdicts so far (skipped when nothing is new), still merged
into the run-start record on the publisher's own context. The ticker is
stopped and its goroutine gone before the final publish.

A sleeping host with no instance record when the bracket opens is now
unverified/no_record, which holds the streak like not_reached and
no_assignment. A record that disappears mid-test stays record_changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev ddfbd4df307d82e089623f7fbc252ed95ca0c397 parent 6de4a16
4 files changed, +296 −72
  • internal/dbverify/dbverify.go +10 −6
  • internal/dbverify/dbverify_test.go +4 −3
  • internal/ops/hibernate_verify.go +93 −25
  • internal/ops/hibernate_verify_test.go +189 −38

CI failed — run details

Intent

Human

<task-notification> <task-id>a620408b003157c26</task-id> <tool-use-id>toolu_016uJ9qnb5Y7o3gxziMxzkmH</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/a620408b003157c26.output</output-file> <status>completed</status> <summary>Agent "Implement slice 2a Task 5" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Status:** DONE_WITH_CONCERNS. Everything in the brief and your rulings is built and passing. **Commit:** `6de4a16f ops: hibernate-verify drills per box, bracketed, on a budget (#898)`, not pushed. **Tests:** `go test ./internal/ops -run 'Hibernat|Verify|OldestFirst'` passes, 34 tests including all 12 the brief names. `TestVerifyDrillsRestoreToDiskNotTmpfs` passes. Build, vet and the darwin/windows builds are clean. Switching off the closing identity check fails 28 bracket subtests, and switching off the lease-owner check fails 4 freshness cases, so those tests do catch regressions. **Concerns:** 1. Two reason codes have no approved copy label, so Task 8 needs them: `plan_moved` (your ruling) and `record_unreadable`. I chose `record_unreadable` for a failed read of the instance's record during a test; rename it if you prefer another code. 2. Sleeping hosts with no instance record will be recorded `unverified`/`record_changed` every night and alert after 3 nights. Before this change they were drilled anyway. Worth checking dev and the flagship before Task 6 arms the timer. 3. The run now exits 1 when `CARLOS_REGION` is invalid or the deployment bucket won't open. The old code drilled anyway and only logged. 4. Hosts cut by the budget, or abandoned at the deadline, get no verdict, so Merge keeps their earlier one or marks a never-seen host `not_reached`. Stamping them `not_reached` would sort them last the next night and they would never get tested. 5. The periodic publish fires after the first host that finishes past each 10-minute mark, not on a wall-clock timer. `internal/ops` is in the root binary; all its new imports were already root dependencies. **Report:** `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups-2a/.superpowers/sdd/2026-11-11-member-backups-slice2a/task-5-report.md`</result> <usage><subagent_tokens>228194</subagent_tokens><tool_uses>57</tool_uses><duration_ms>1070181</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>b0sodaoa5</task-id> <tool-use-id>toolu_01JXosCRnYscZh2b2YMYpXwV</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/b0sodaoa5.output</output-file> <status>completed</status> <summary>Background command "Ledger rulings; start Astra review of Task 5" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 13.9 g CO₂e (1,770,098 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on member-backups-2a, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/internal/dbverify/dbverify.go b/internal/dbverify/dbverify.go
index 254a90b09..5e53bc3e2 100644
--- a/internal/dbverify/dbverify.go
+++ b/internal/dbverify/dbverify.go
@@ -63,11 +63,14 @@ const (
// ReasonNotReached is an unverified verdict for a host the run did not
// get to, or abandoned when it ran out of time; ReasonNoAssignment is one
-// for a group box's host that no usable assignment gave this box. Neither
-// learned anything about the replica, so neither moves UnverifiedRuns.
+// for a group box's host that no usable assignment gave this box;
+// ReasonNoRecord is one for a host with no instance record when the test
+// began, so there was no instance to bind a test to. None of them learned
+// anything about the replica, so none moves UnverifiedRuns.
const (
ReasonNotReached = "not_reached"
ReasonNoAssignment = "no_assignment"
+ ReasonNoRecord = "no_record"
)
// Identity is the instance a verdict is about. It mirrors dbreads.Identity
@@ -117,8 +120,8 @@ type Verdict struct {
// The bookkeeping Merge keeps, whatever the caller set.
//
// UnverifiedRuns is how many runs in a row ended unverified, not
- // counting not_reached or no_assignment runs, which leave it as it
- // was; passed or failed sets it to 0.
+ // counting not_reached, no_assignment or no_record runs, which leave
+ // it as it was; passed or failed sets it to 0.
UnverifiedRuns int `json:"unverified_runs"`
// FirstSeen is the first run that counted this host, for this
// identity.
@@ -160,7 +163,8 @@ type Record struct {
// For each result, Merge keeps the host's bookkeeping: FirstSeen carries
// over, LastDecidedAt advances only on passed or failed, and
// UnverifiedRuns counts unverified runs in a row: passed or failed resets
-// it, not_reached and no_assignment hold it, any other reason adds one.
+// it, not_reached, no_assignment and no_record hold it, any other reason
+// adds one.
// A result about a different identity than the prior verdict starts all
// three over. A result with no identity (zero) keeps the prior verdict's
// last known one; a prior with none is never "different".
@@ -212,7 +216,7 @@ func mergeOne(p Verdict, had bool, r Verdict, now time.Time) Verdict {
r.LastDecidedAt = now
}
case ResultUnverified:
- if r.Reason == ReasonNotReached || r.Reason == ReasonNoAssignment {
+ if r.Reason == ReasonNotReached || r.Reason == ReasonNoAssignment || r.Reason == ReasonNoRecord {
r.UnverifiedRuns = p.UnverifiedRuns // held: nothing was tried
} else {
r.UnverifiedRuns = p.UnverifiedRuns + 1
diff --git a/internal/dbverify/dbverify_test.go b/internal/dbverify/dbverify_test.go
index 2a2191f82..fcf0c9621 100644
--- a/internal/dbverify/dbverify_test.go
+++ b/internal/dbverify/dbverify_test.go
@@ -154,10 +154,11 @@ func TestMergeUnverifiedRuns(t *testing.T) {
}
}
-// A run that never reached the host (not_reached, or no_assignment on a
-// group box) learned nothing: it neither adds to the streak nor ends it.
+// A run that never reached the host (not_reached, no_assignment on a group
+// box, or no_record for a host with no instance record to bind a test to)
+// learned nothing: it neither adds to the streak nor ends it.
func TestMergeNotReachedHoldsTheStreak(t *testing.T) {
- for _, reason := range []string{ReasonNotReached, ReasonNoAssignment} {
+ for _, reason := range []string{ReasonNotReached, ReasonNoAssignment, ReasonNoRecord} {
fleet := []string{"a.example.com"}
day := at("2026-08-01T03:00:00Z")
var rec *Record
diff --git a/internal/ops/hibernate_verify.go b/internal/ops/hibernate_verify.go
index 6b892ac25..d5e034f0d 100644
--- a/internal/ops/hibernate_verify.go
+++ b/internal/ops/hibernate_verify.go
@@ -24,6 +24,7 @@ import (
"os"
"slices"
"sort"
+ "sync"
"time"
"github.com/benbjohnson/litestream"
@@ -119,6 +120,12 @@ var (
verifyAt = lease.VerifyReplicaAt
lockState = lease.LockState
localFreshness = hibernateFreshness
+ // publishTicker is the run's publication clock: ticks every d, and a
+ // stop.
+ publishTicker = func(d time.Duration) (<-chan time.Time, func()) {
+ t := time.NewTicker(d)
+ return t.C, t.Stop
+ }
)
// Drill is one run's settings. Cfg names the hibernate bucket; Store is the
@@ -130,9 +137,9 @@ var (
// Budget is the run's deadline (none when zero): no host starts once it is
// spent by the run's clock, and the context every step runs under ends
// when it passes, so a restore blocked in its download is abandoned too.
-// Max caps the hosts drilled (none when zero). PublishEvery is how often
-// the run hands what it has finished to its publisher (only at the end
-// when zero).
+// Max caps the hosts drilled (none when zero). PublishEvery is how often,
+// by the wall clock, the run hands what it has finished to its publisher
+// (only at the end when zero).
type Drill struct {
Cfg *activator.Config
Store release.Store
@@ -153,10 +160,14 @@ type Drill struct {
// than one run's budget is still covered completely, just over several
// nights.
//
-// publish (when not nil) is handed everything finished so far at the first
-// host boundary past each PublishEvery mark and once at the end, always
-// from this goroutine. It must publish under its own context: the run's
-// may have ended by then.
+// publish (when not nil) is handed everything finished so far on a
+// wall-clock ticker every PublishEvery, whatever the host in progress is
+// doing, so a restore blocked for half an hour does not hold back the
+// verdicts finished before it, and once more at the end. A tick with
+// nothing new finished since the last publish is skipped. publish is never
+// called twice at once, and never after VerifyHibernating returns: the
+// ticker is stopped and its goroutine gone before the final publish. It
+// must publish under its own context: the run's may have ended by then.
//
// Each host is bracketed (P-11): its record is read before planning and
// again after the last replica byte, and any difference discards what the
@@ -170,13 +181,35 @@ func VerifyHibernating(ctx context.Context, d Drill, hosts []HibernatingRoute, n
}
defer cancel()
- out := map[string]dbverify.Verdict{}
- snapshot := func() {
- if publish != nil {
- publish(cloneVerdicts(out))
- }
+ var res runResults
+ if publish != nil && d.PublishEvery > 0 {
+ ticks, stopTicker := publishTicker(d.PublishEvery)
+ done, exited := make(chan struct{}), make(chan struct{})
+ go func() {
+ defer close(exited)
+ for {
+ select {
+ case <-done:
+ return
+ case <-ticks:
+ if snap, ok := res.unpublished(); ok {
+ publish(snap)
+ }
+ }
+ }
+ }()
+ // Runs before the final publish below: the ticker stops and the
+ // goroutine has returned, so no tick publishes after it.
+ defer func() {
+ stopTicker()
+ close(done)
+ <-exited
+ publish(res.all())
+ }()
+ } else if publish != nil {
+ defer func() { publish(res.all()) }()
}
- next := start.Add(d.PublishEvery)
+
visited := 0
for _, rt := range hosts {
if d.Max > 0 && visited >= d.Max {
@@ -196,19 +229,48 @@ func VerifyHibernating(ctx context.Context, d Drill, hosts []HibernatingRoute, n
fmt.Printf("abandoned %s: the run ended during its test; no verdict\n", rt.Host)
continue
}
- out[rt.Host] = v
+ res.add(rt.Host, v)
printVerdict(rt.Host, v)
- if d.PublishEvery > 0 {
- if t := now(); !t.Before(next) {
- for !t.Before(next) {
- next = next.Add(d.PublishEvery)
- }
- snapshot()
- }
- }
}
- snapshot()
- return out
+ return res.all()
+}
+
+// runResults is a run's verdicts so far, shared by the drill and the
+// publish ticker.
+type runResults struct {
+ mu sync.Mutex
+ out map[string]dbverify.Verdict
+ version int // bumped by every add
+ published int // the version the last ticker publish carried
+}
+
+func (r *runResults) add(host string, v dbverify.Verdict) {
+ r.mu.Lock()
+ defer r.mu.Unlock()
+ if r.out == nil {
+ r.out = map[string]dbverify.Verdict{}
+ }
+ r.out[host] = v
+ r.version++
+}
+
+// all is a copy of every verdict so far.
+func (r *runResults) all() map[string]dbverify.Verdict {
+ r.mu.Lock()
+ defer r.mu.Unlock()
+ return cloneVerdicts(r.out)
+}
+
+// unpublished is a copy of every verdict so far, when something was added
+// since the last time it said so.
+func (r *runResults) unpublished() (map[string]dbverify.Verdict, bool) {
+ r.mu.Lock()
+ defer r.mu.Unlock()
+ if r.version == r.published {
+ return nil, false
+ }
+ r.published = r.version
+ return cloneVerdicts(r.out), true
}
func cloneVerdicts(m map[string]dbverify.Verdict) map[string]dbverify.Verdict {
@@ -259,7 +321,7 @@ func (d Drill) drillOne(ctx context.Context, rt HibernatingRoute, now func() tim
return v, true
}
- id, _, code, err := dbreads.CaptureIdentity(ctx, d.Store, d.Region, rt.Account, rt.App, rt.Host)
+ id, rec, code, err := dbreads.CaptureIdentity(ctx, d.Store, d.Region, rt.Account, rt.App, rt.Host)
if err != nil {
if ctx.Err() != nil {
return dbverify.Verdict{}, false
@@ -267,6 +329,12 @@ func (d Drill) drillOne(ctx context.Context, rt HibernatingRoute, now func() tim
return unverified(ReasonRecordUnreadable, err.Error())
}
v.Identity = dbverify.Identity(id)
+ if code == dbreads.CodeRecordChanged && rec.Host == "" {
+ // No record at all when the test began (CaptureIdentity's zero
+ // record): there is no instance to bind a test to. It holds the
+ // streak, unlike a record that refuses or changes.
+ return unverified(dbverify.ReasonNoRecord, "this box has the host, but there is no instance record for it")
+ }
if code != "" {
return unverified(bracketReason(code), "the instance's record refused the test when it began")
}
diff --git a/internal/ops/hibernate_verify_test.go b/internal/ops/hibernate_verify_test.go
index 913f099b4..4f4267f55 100644
--- a/internal/ops/hibernate_verify_test.go
+++ b/internal/ops/hibernate_verify_test.go
@@ -674,27 +674,93 @@ func TestVerifyHibernatingBracket(t *testing.T) {
// A record that already refuses when the bracket opens is not drilled.
func TestVerifyHibernatingRefusesBeforePlanning(t *testing.T) {
- fx := newDrillFx(t, "moving.example.com")
+ fx := newDrillFx(t, "moving.example.com", "elsewhere.example.com", "retired.example.com")
fx.putRecord(fxAccount, "moving.example.com", time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC), func(r *provision.Record) {
r.Move = &provision.MoveState{ID: "mv_x", To: "ie", State: "requested"}
})
+ fx.putRecord(fxAccount, "elsewhere.example.com", time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC), func(r *provision.Record) {
+ r.Region = "ie"
+ })
+ // provision.GetRecord reads a retired record as absent: no instance.
+ fx.putRecord(fxAccount, "retired.example.com", time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC), func(r *provision.Record) {
+ r.Retired = true
+ })
planned := false
swap(t, &openReplica, func(context.Context, string, string, string) (dbdoor.ReplicaReader, error) {
planned = true
return nil, errors.New("not reached")
})
- got := fx.run(context.Background(), fx.drill(), fx.routes("moving.example.com", "gone.example.com"), nil)
+ got := fx.run(context.Background(), fx.drill(), fx.routes("moving.example.com", "elsewhere.example.com", "retired.example.com", "gone.example.com"), nil)
if planned {
t.Fatal("a refused capture went on to plan")
}
if v := got["moving.example.com"]; v.Reason != ReasonMoving || !v.Unverified() || v.Identity.Host != "moving.example.com" {
t.Fatalf("moving: %+v", v)
}
- if v := got["gone.example.com"]; v.Reason != ReasonRecordChanged || !v.Unverified() {
- t.Fatalf("no record: %+v", v)
+ if v := got["elsewhere.example.com"]; v.Reason != ReasonRecordChanged || !v.Unverified() {
+ t.Fatalf("a record that refuses: %+v, want record_changed", v)
+ }
+ for _, h := range []string{"retired.example.com", "gone.example.com"} {
+ if v := got[h]; v.Reason != dbverify.ReasonNoRecord || !v.Unverified() {
+ t.Fatalf("%s, no record: %+v, want no_record", h, v)
+ }
}
}
+// TestVerifyHibernatingNoRecordOnlyAtCapture: a sleeping host with no
+// instance record when the bracket opens is no_record, which holds the
+// streak, so night after night it never raises the unverified alert. A
+// record that disappears after the bracket opened is a change during the
+// test: record_changed, which counts.
+func TestVerifyHibernatingNoRecordOnlyAtCapture(t *testing.T) {
+ const host = "shop.example.com"
+ nights := func(t *testing.T, fx *drillFx, reset func()) (dbverify.Verdict, int) {
+ t.Helper()
+ var rec *dbverify.Record
+ var v dbverify.Verdict
+ for i := 0; i < 4; i++ {
+ reset()
+ v = fx.run(context.Background(), fx.drill(), fx.routes(host), nil)[host]
+ rec = dbverify.Merge(rec, fxSelf, fx.clock.Now(), []string{host}, map[string]dbverify.Verdict{host: v})
+ fx.clock.Advance(24 * time.Hour)
+ }
+ return v, rec.Hosts[host].UnverifiedRuns
+ }
+ t.Run("missing when the bracket opens", func(t *testing.T) {
+ fx := newDrillFx(t)
+ restored := false
+ fx.stubVerify(func(context.Context, string, string, uint64) (uint32, error) {
+ restored = true
+ return 1, nil
+ })
+ v, streak := nights(t, fx, func() {})
+ if !v.Unverified() || v.Reason != dbverify.ReasonNoRecord {
+ t.Fatalf("verdict %+v, want unverified/no_record", v)
+ }
+ if restored {
+ t.Fatal("a host with no record was restored")
+ }
+ if streak != 0 {
+ t.Fatalf("four no_record nights left a streak of %d, want 0", streak)
+ }
+ })
+ t.Run("deleted after the bracket opened", func(t *testing.T) {
+ fx := newDrillFx(t)
+ created := time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC)
+ fx.stubVerify(func(context.Context, string, string, uint64) (uint32, error) {
+ fx.deleteRecord(fxAccount, host)
+ return 1, nil
+ })
+ v, streak := nights(t, fx, func() { fx.putRecord(fxAccount, host, created, nil) })
+ if !v.Unverified() || v.Reason != ReasonRecordChanged {
+ t.Fatalf("verdict %+v, want unverified/record_changed", v)
+ }
+ if streak != 4 {
+ t.Fatalf("four record_changed nights left a streak of %d, want 4", streak)
+ }
+ })
+}
+
// Compaction between the plan and the restore makes the planned position
// unrestorable: not a failure. The drill plans again once; twice is
// unverified, plan_moved.
@@ -939,50 +1005,126 @@ func TestVerifyHibernatingDeadlineStopsBlockedWork(t *testing.T) {
}
}
-// TestVerifyHibernatingPublishesPeriodically: a publish at each interval
-// mark with everything finished so far, and one at the end; a run killed
-// between marks has what the last publish held in the bucket.
+// manualTicker replaces the publish ticker: the test decides when a tick
+// arrives, and learns when the ticker was stopped.
+type manualTicker struct {
+ c chan time.Time
+ stopped atomic.Bool
+}
+
+func swapTicker(t *testing.T) *manualTicker {
+ t.Helper()
+ m := &manualTicker{c: make(chan time.Time)}
+ swap(t, &publishTicker, func(d time.Duration) (<-chan time.Time, func()) {
+ if d != 10*time.Minute {
+ t.Errorf("ticker every %s, want the run's 10m", d)
+ }
+ return m.c, func() { m.stopped.Store(true) }
+ })
+ return m
+}
+
+// TestVerifyHibernatingPublishesPeriodically: publication follows the
+// clock, not the hosts. One host finishes at minute 4, the next blocks in
+// its download; the 10-minute tick still publishes the first, so a crash
+// during the blocked host loses nothing finished. The final publish
+// follows the end of the run, and after it the ticker is stopped and
+// nothing publishes again.
func TestVerifyHibernatingPublishesPeriodically(t *testing.T) {
- var hosts []string
- for i := 0; i < 7; i++ {
- hosts = append(hosts, fmt.Sprintf("h%d.example.com", i))
- }
+ hosts := []string{"a.example.com", "b.example.com"}
fx := newDrillFx(t, hosts...)
store := &ctxStore{Store: fx.store}
fx.store = store
- var atSeventh *dbverify.Record
- fx.stubVerify(func(_ context.Context, prefix, _ string, _ uint64) (uint32, error) {
- if strings.HasSuffix(prefix, "h6.example.com") {
- // What a kill here would leave in the bucket.
- atSeventh, _ = dbverify.Load(context.Background(), store, fxSelf)
+ ticker := swapTicker(t)
+ blocked, release := make(chan struct{}), make(chan struct{})
+ fx.stubVerify(func(ctx context.Context, prefix, _ string, _ uint64) (uint32, error) {
+ if strings.HasSuffix(prefix, "a.example.com") {
+ fx.clock.Advance(4 * time.Minute)
+ return 1, nil
}
- fx.clock.Advance(4 * time.Minute)
+ fx.clock.Advance(6 * time.Minute)
+ close(blocked)
+ <-release
return 1, nil
})
d := fx.drill()
d.PublishEvery = 10 * time.Minute
- var sizes []int
pub := newVerifyPublisher(context.Background(), store, fxSelf, nil, hosts, nil, t.TempDir(), fx.clock.Now, t.Logf)
- fx.run(context.Background(), d, fx.routes(hosts...), func(r map[string]dbverify.Verdict) {
- sizes = append(sizes, len(r))
- pub.publish(r)
- })
- // Hosts end at 4, 8, 12, 16, 20, 24 and 28 minutes: the 10-minute mark
- // is first seen at 12, the 20-minute one at 20, then the end.
- if !slices.Equal(sizes, []int{3, 5, 7}) {
- t.Fatalf("published with %v verdicts, want [3 5 7]", sizes)
- }
- if atSeventh == nil {
- t.Fatal("nothing in the bucket before the last host")
- }
- passed := 0
- for _, v := range atSeventh.Hosts {
- if v.OK() {
- passed++
- }
+ published := make(chan map[string]dbverify.Verdict, 8)
+ done := make(chan map[string]dbverify.Verdict)
+ go func() {
+ done <- fx.run(context.Background(), d, fx.routes(hosts...), func(r map[string]dbverify.Verdict) {
+ pub.publish(r)
+ published <- r
+ })
+ }()
+
+ <-blocked
+ ticker.c <- fx.clock.Now() // the 10-minute mark, b still blocked
+ got := <-published
+ if _, ok := got["a.example.com"]; !ok || len(got) != 1 {
+ t.Fatalf("the 10-minute publish held %v, want a.example.com alone", got)
+ }
+ // What a crash now would leave in the bucket.
+ rec, err := dbverify.Load(context.Background(), store, fxSelf)
+ if err != nil || rec == nil || !rec.Hosts["a.example.com"].OK() {
+ t.Fatalf("after the 10-minute publish the bucket holds %+v, %v", rec, err)
+ }
+ if v := rec.Hosts["b.example.com"]; v.Reason != dbverify.ReasonNotReached {
+ t.Fatalf("the blocked host published as %+v", v)
+ }
+
+ close(release)
+ final := <-done
+ if got := <-published; len(got) != 2 || len(final) != 2 {
+ t.Fatalf("final publish held %d verdicts, the run returned %d; want 2 and 2", len(got), len(final))
}
- if passed != 5 {
- t.Fatalf("a run killed during the seventh host leaves %d passes in the bucket, want 5", passed)
+ if !ticker.stopped.Load() {
+ t.Fatal("the ticker was not stopped")
+ }
+ select {
+ case ticker.c <- fx.clock.Now():
+ t.Fatal("a tick was taken after the run ended")
+ case <-time.After(50 * time.Millisecond):
+ }
+ select {
+ case r := <-published:
+ t.Fatalf("published after the final publish: %v", r)
+ default:
+ }
+ if n := len(store.published()); n != 2 {
+ t.Fatalf("%d publishes, want the tick's and the final one", n)
+ }
+}
+
+// A tick with nothing new finished since the last publish writes nothing.
+func TestVerifyHibernatingTickWithNothingNewIsQuiet(t *testing.T) {
+ fx := newDrillFx(t, "a.example.com")
+ ticker := swapTicker(t)
+ blocked, release := make(chan struct{}), make(chan struct{})
+ fx.stubVerify(func(context.Context, string, string, uint64) (uint32, error) {
+ close(blocked)
+ <-release
+ return 1, nil
+ })
+ d := fx.drill()
+ d.PublishEvery = 10 * time.Minute
+ var calls atomic.Int32
+ done := make(chan struct{})
+ go func() {
+ fx.run(context.Background(), d, fx.routes("a.example.com"), func(map[string]dbverify.Verdict) { calls.Add(1) })
+ close(done)
+ }()
+ <-blocked
+ ticker.c <- fx.clock.Now()
+ ticker.c <- fx.clock.Now() // taken only once the first tick was handled
+ if n := calls.Load(); n != 0 {
+ t.Fatalf("%d publishes with nothing finished", n)
+ }
+ close(release)
+ <-done
+ if n := calls.Load(); n != 1 {
+ t.Fatalf("%d publishes, want the final one", n)
}
}
@@ -1005,15 +1147,24 @@ func TestVerifyHibernatingStreakOncePerRun(t *testing.T) {
if err := dbverify.Publish(context.Background(), store, prior); err != nil {
t.Fatal(err)
}
+ ticker := swapTicker(t)
+ published := make(chan struct{}, 8)
+ // Each drilled host ticks once while it runs, after the previous host's
+ // verdict is in: four periodic publishes, then the final one.
fx.stubVerify(func(context.Context, string, string, uint64) (uint32, error) {
fx.clock.Advance(10 * time.Minute)
+ ticker.c <- fx.clock.Now()
+ <-published
return 1, nil
})
d := fx.drill()
d.PublishEvery = 10 * time.Minute
pub := newVerifyPublisher(context.Background(), store, fxSelf, prior, hosts, nil, t.TempDir(), fx.clock.Now, t.Logf)
// The unverified host first, so every publish of the run carries it.
- fx.run(context.Background(), d, fx.routes(hosts...), pub.publish)
+ fx.run(context.Background(), d, fx.routes(hosts...), func(r map[string]dbverify.Verdict) {
+ pub.publish(r)
+ published <- struct{}{}
+ })
puts := store.published()[1:] // the seeded prior is the first
if len(puts) != 5 {