carlos / platform Public

activator: heldPoll is a var, so held-wake tests can shrink it

A held wake asks for its answer again every heldReask (8) polls of
heldPoll (250 ms), so each test waiting on a re-ask waited about 2 s.
The const becomes a var with the same value; those tests poll every
25 ms, and their wake bounds shrink in step (1.9 s to 0.4 s, 3 s to 1 s),
still well past the re-ask they wait for.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 6bef28bea5b03bfb76de0fc56f2c231beb348ca9 parent 6ad588a
2 files changed, +22 −5
  • internal/activator/wakecheck.go +2 −2
  • internal/activator/wakecheck_test.go +20 −3
diff --git a/internal/activator/wakecheck.go b/internal/activator/wakecheck.go
index 803840d9b..e476eebc9 100644
--- a/internal/activator/wakecheck.go
+++ b/internal/activator/wakecheck.go
@@ -52,8 +52,8 @@ type HeldWake struct {
}
// heldPoll is how often a held wake re-reads the live link while it waits
-// for root to install its target.
-const heldPoll = 250 * time.Millisecond
+// for root to install its target. A var so tests can shrink it.
+var heldPoll = 250 * time.Millisecond
// wakeCheck is settings spec §4.3 rule 3's wake half, with its own admission
// rule so it holds with CARLOS_SWAP off and no planner (Astra I3 #2, #5):
diff --git a/internal/activator/wakecheck_test.go b/internal/activator/wakecheck_test.go
index a7275ea85..9c80eb595 100644
--- a/internal/activator/wakecheck_test.go
+++ b/internal/activator/wakecheck_test.go
@@ -33,6 +33,16 @@ func shrinkWakeWait(t *testing.T, d time.Duration) {
t.Cleanup(func() { wakeWaitBound = old })
}
+// shrinkHeldPoll sets how often a held wake polls while it waits, for one
+// test. It asks for the answer again every heldReask polls, so a test that
+// waits for a re-ask waits heldReask*d.
+func shrinkHeldPoll(t *testing.T, d time.Duration) {
+ t.Helper()
+ old := heldPoll
+ heldPoll = d
+ t.Cleanup(func() { heldPoll = old })
+}
+
// asks records RequestStage calls as host@build.
type asks struct {
mu sync.Mutex
@@ -486,6 +496,7 @@ func TestAHeldWakeEndsItsWaitWhenTheAnswerChanges(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
shrinkWakeWait(t, 20*time.Second)
+ shrinkHeldPoll(t, 25*time.Millisecond) // the re-ask comes 8 polls in
a, b := identityActivator(t, "v3")
var asked atomic.Int32
a.HeldTarget = func(string) HeldWake {
@@ -563,7 +574,10 @@ func TestAHeldUnitRowRefusesALinkThatMovedAfterTheWait(t *testing.T) {
// to come back (the agent's refresh reads the bucket, up to its own 5 s
// budget) never holds the wake past wakeWaitBound.
func TestAHeldWakesReaskNeverOutlastsTheWait(t *testing.T) {
- shrinkWakeWait(t, 1900*time.Millisecond)
+ // The re-ask comes 8 polls (175 ms) into a 400 ms wait, and its answer
+ // takes 5 s: the wait must end at its own bound.
+ shrinkHeldPoll(t, 25*time.Millisecond)
+ shrinkWakeWait(t, 400*time.Millisecond)
a, b := identityActivator(t, "v3")
var asked atomic.Int32
a.HeldTarget = func(string) HeldWake {
@@ -586,7 +600,7 @@ func TestAHeldWakesReaskNeverOutlastsTheWait(t *testing.T) {
t.Fatalf("asked %d times: the wait never asked again", asked.Load())
}
if took >= 3*time.Second {
- t.Fatalf("the wait ran %v, past its 1.9 s bound: the re-ask outlasted it", took)
+ t.Fatalf("the wait ran %v, past its 0.4 s bound: the re-ask outlasted it", took)
}
if b.startCount() != 0 {
t.Fatal("a wake that never saw its target ran something")
@@ -643,7 +657,10 @@ func TestAWakeRootHasNotDecidedForWaitsForRoot(t *testing.T) {
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
- shrinkWakeWait(t, 3*time.Second)
+ // Root's answer is asked again 8 polls (200 ms) in; a wake root
+ // never decides for fails at the bound.
+ shrinkHeldPoll(t, 25*time.Millisecond)
+ shrinkWakeWait(t, time.Second)
a, b := identityActivator(t, "v3")
var asked atomic.Bool
a.HeldTarget = func(string) HeldWake {