carlos / platform Public

tests: end the rotation test's passes from the read, not a timer

TestRefreshAllRotatesPastWhereTheLastOneStopped gave each refreshAll a
200 ms budget and relied on the first host's read being reached inside
it. The budget starts before the registry List, so on a loaded hosted
runner a slow List spent it before any host was read and the pass
skipped all three ("pass 1 skipped 3, want 2", also seen at pass 3).
A 250 ms sleep after List reproduces it every time.

The store double now ends the pass by cancelling the caller's context
when it is first read, and the budget is a minute, so the pass stops
exactly after one host whatever the runner's speed. The deadline path
itself stays covered by the nanosecond-budget test. Removing the
resume bookkeeping still fails the test. Test-only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev a9b6f5f9136b840269c91ffc74e8a0291f10362f parent a178a75
1 file changed, +18 −5
  • internal/host/buildstate_test.go +18 −5

CI failed — run details

Intent

Attributed to this commit: 235 g CO₂e (26,710,889 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on refresh-rotate-test, 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/host/buildstate_test.go b/internal/host/buildstate_test.go
index 0be283fcf..acc2da7ed 100644
--- a/internal/host/buildstate_test.go
+++ b/internal/host/buildstate_test.go
@@ -1113,20 +1113,27 @@ func TestAHeldWakeReadsTheCopyAsRootsTargetDoes(t *testing.T) {
}
}
-// budgetEater records which host's build state each read asks for and
-// holds the read until the caller's context ends: the host it is reading
-// spends the whole refresh budget.
+// budgetEater records which host's build state each read asks for, ends
+// the pass (spend) and holds the read until the caller's context ends: the
+// host it is reading spends the whole refresh budget. Ending the pass from
+// the read, not from a short wall-clock budget, keeps a slow registry list
+// on a loaded runner from spending the budget before any host is reached.
type budgetEater struct {
release.Store
mu sync.Mutex
hosts []string
+ spend context.CancelFunc
}
func (e *budgetEater) Get(ctx context.Context, key string) ([]byte, string, error) {
if host, ok := strings.CutSuffix(strings.TrimPrefix(key, "inst/"), "/build-state.json"); ok {
e.mu.Lock()
e.hosts = append(e.hosts, host)
+ spend := e.spend
e.mu.Unlock()
+ if spend != nil {
+ spend()
+ }
<-ctx.Done()
return nil, "", ctx.Err()
}
@@ -1146,9 +1153,15 @@ func TestRefreshAllRotatesPastWhereTheLastOneStopped(t *testing.T) {
}
eater := &budgetEater{Store: s}
b.storeFor = storesOf(map[string]release.Store{"hib": eater})
- b.budget = 200 * time.Millisecond
+ b.budget = time.Minute
for i := 0; i < 4; i++ {
- if skipped := b.refreshAll(context.Background()); skipped != 2 {
+ ctx, spend := context.WithCancel(context.Background())
+ eater.mu.Lock()
+ eater.spend = spend
+ eater.mu.Unlock()
+ skipped := b.refreshAll(ctx)
+ spend()
+ if skipped != 2 {
t.Fatalf("pass %d skipped %d, want 2 (one host eats the budget)", i, skipped)
}
}