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.
Merged on green tip 6e97f72d onto main 27d3f501 without a re-run, per agent
manager 8a3d302: no commit main gained since 293881ad touches this
branch's files, and the combined tree (local, not pushed) passes
go vet ./internal/host and go test ./internal/host -run '^TestRefreshAllRotatesPastWhereTheLastOneStopped$' -count=3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Squashed from refresh-rotate-test into main.
1 file changed,
+18
−5
internal/host/buildstate_test.go+18 −5
CI passed — run details
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) |
| } |
| } |