carlos / platform Public

ops: deterministic quiet-tick drill test (publishTickDone hook)

TestVerifyHibernatingTickWithNothingNewIsQuiet flaked (5 in 200): its
second tick's send returned on receipt, and that tick's handling could
run after the released host's verdict landed and rightly publish it. The
publish goroutine now calls publishTickDone after handling each tick (a
no-op in production); the test waits on it before checking and before
releasing the host. Assertions unchanged. 500/500 and -race clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 8a79cf14ac63f816e1f0dd905a52790b85758786 parent ecb11bf
2 files changed, +17 −4
  • internal/ops/hibernate_verify.go +6 −0
  • internal/ops/hibernate_verify_test.go +11 −4
diff --git a/internal/ops/hibernate_verify.go b/internal/ops/hibernate_verify.go
index d5e034f0d..fbf5c5382 100644
--- a/internal/ops/hibernate_verify.go
+++ b/internal/ops/hibernate_verify.go
@@ -126,6 +126,11 @@ var (
t := time.NewTicker(d)
return t.C, t.Stop
}
+ // publishTickDone is called once each tick has been handled (published,
+ // or skipped with nothing new). Production does nothing; a test waits
+ // on it, since a tick's receipt says nothing about when its handling
+ // ends.
+ publishTickDone = func() {}
)
// Drill is one run's settings. Cfg names the hibernate bucket; Store is the
@@ -195,6 +200,7 @@ func VerifyHibernating(ctx context.Context, d Drill, hosts []HibernatingRoute, n
if snap, ok := res.unpublished(); ok {
publish(snap)
}
+ publishTickDone()
}
}
}()
diff --git a/internal/ops/hibernate_verify_test.go b/internal/ops/hibernate_verify_test.go
index 4f4267f55..1ea06165b 100644
--- a/internal/ops/hibernate_verify_test.go
+++ b/internal/ops/hibernate_verify_test.go
@@ -1107,6 +1107,11 @@ func TestVerifyHibernatingTickWithNothingNewIsQuiet(t *testing.T) {
<-release
return 1, nil
})
+ // A tick's receipt says nothing about when its handling ends: wait for
+ // publishTickDone, so no tick is still being handled when the host's
+ // verdict lands (that tick would rightly publish it).
+ handled := make(chan struct{})
+ swap(t, &publishTickDone, func() { handled <- struct{}{} })
d := fx.drill()
d.PublishEvery = 10 * time.Minute
var calls atomic.Int32
@@ -1116,10 +1121,12 @@ func TestVerifyHibernatingTickWithNothingNewIsQuiet(t *testing.T) {
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)
+ for range 2 {
+ ticker.c <- fx.clock.Now()
+ <-handled
+ if n := calls.Load(); n != 0 {
+ t.Fatalf("%d publishes with nothing finished", n)
+ }
}
close(release)
<-done