test(durable): wall-clock tests wait for their events with deadline-aware budgets

The chunk authority log tests waited 2 s for a log line and gave the open a
2 s context; the timer cut test required eight refusals in 2.5 s and gaps of
at most 400 ms. Two test jobs on one host stretch those. They now wait for
the event with a budget of up to 30 s, never past the test's own deadline;
the timer test keeps its rule (the slot wait polls, it does not take the
failure backoff) by bounds the backoff cannot meet: eight refusals, no gap
and no admission delay above 3 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-30 11:46:48 -08:00
1 parent b08d9a3dd4
commit ef6e250ee1
2 files changed
+45 -20

No files matched your search

@@ -106,21 +106,33 @@ func refusedAt(events []admitEvent) []time.Time {
return at
}
// A timer cut refused because every host slot is held is retried within
// one poll plus the largest retry delay, every time, however long the
// slot is held; once it frees, the next attempt is admitted within that
// bound. Times are the limiter's own Admit calls.
// A timer cut refused because every host slot is held keeps being retried by
// the slot wait's poll, not by the failure backoff (1 s, 2 s, 4 s, ...); once
// the slot frees, the next attempt is admitted. Times are the limiter's own
// Admit calls. The test waits for events, with bounds wide enough for a
// loaded runner yet far below what the backoff would take: eight refusals
// within the outer budget, no gap above slotGapLimit (the backoff's eighth
// gap would be 64 s), and the admission within slotGapLimit of the release.
const slotGapLimit = 3 * time.Second
func TestTimerCutRunsSoonAfterHostSlotFrees(t *testing.T) {
p, lim, c, release, baseGen := slotWaitProvider(t)
time.Sleep(2500 * time.Millisecond)
refusals := refusedAt(lim.snapshot())
// A failure backoff (1 s, 2 s, ...) allows at most 3 attempts in 2.5 s.
if len(refusals) < 8 {
t.Fatalf("%d refused admissions in 2.5 s; a slot wait retries every <= 300 ms", len(refusals))
budget := 30 * time.Second
if dl, ok := t.Deadline(); ok && time.Until(dl)-10*time.Second < budget {
budget = max(time.Until(dl)-10*time.Second, 5*time.Second)
}
var refusals []time.Time
for deadline := time.Now().Add(budget); ; time.Sleep(10 * time.Millisecond) {
if refusals = refusedAt(lim.snapshot()); len(refusals) >= 8 {
break
}
if time.Now().After(deadline) {
t.Fatalf("%d refused admissions in %s; a slot wait retries by its poll, not by the failure backoff", len(refusals), budget)
}
}
for i := 1; i < len(refusals); i++ {
if gap := refusals[i].Sub(refusals[i-1]); gap > 400*time.Millisecond {
t.Fatalf("admission %d came %s after the previous refusal", i, gap)
if gap := refusals[i].Sub(refusals[i-1]); gap > slotGapLimit {
t.Fatalf("admission %d came %s after the previous refusal (the failure backoff, not the slot poll)", i, gap)
}
}
if admitted(lim.snapshot()) {
@@ -137,7 +149,7 @@ func TestTimerCutRunsSoonAfterHostSlotFrees(t *testing.T) {
freed := time.Now()
release()
var admittedAt time.Time
for deadline := time.Now().Add(5 * time.Second); admittedAt.IsZero(); time.Sleep(10 * time.Millisecond) {
for deadline := time.Now().Add(budget); admittedAt.IsZero(); time.Sleep(10 * time.Millisecond) {
for _, e := range lim.snapshot()[before:] {
if e.ok {
admittedAt = e.at
@@ -145,21 +157,21 @@ func TestTimerCutRunsSoonAfterHostSlotFrees(t *testing.T) {
}
}
if admittedAt.IsZero() && time.Now().After(deadline) {
t.Fatal("no cut admitted within 5 s of the slot freeing")
t.Fatalf("no cut admitted within %s of the slot freeing", budget)
}
}
if d := admittedAt.Sub(freed); d > 400*time.Millisecond {
t.Fatalf("the first admission came %s after the slot freed; want <= 400 ms", d)
if d := admittedAt.Sub(freed); d > slotGapLimit {
t.Fatalf("the first admission came %s after the slot freed; want the next poll, <= %s", d, slotGapLimit)
}
for deadline := time.Now().Add(5 * time.Second); ; time.Sleep(10 * time.Millisecond) {
for deadline := time.Now().Add(budget); ; time.Sleep(10 * time.Millisecond) {
if h := c.head(t); h.Gen > baseGen {
break
}
if time.Now().After(deadline) {
t.Fatal("the admitted cut did not publish within 5 s")
t.Fatalf("the admitted cut did not publish within %s", budget)
}
}
for deadline := time.Now().Add(time.Second); ; time.Sleep(10 * time.Millisecond) {
for deadline := time.Now().Add(budget); ; time.Sleep(10 * time.Millisecond) {
if cs := chunkStatus(t, p).CutSchedule; cs != nil && cs.HostSlotWaitSinceNs == 0 && cs.HostSlotWaits >= uint64(len(refusals)) {
break
}
@@ -32,10 +32,23 @@ func (l *lockedLog) String() string {
return l.buf.String()
}
// eventBudget is how long a test waits for an event it polls for: generous,
// since a loaded runner (two test jobs on one host) can take seconds; never
// past the test's own deadline less a reserve.
func eventBudget(t *testing.T) time.Duration {
budget := 30 * time.Second
if dl, ok := t.Deadline(); ok {
if left := time.Until(dl) - 5*time.Second; left < budget {
budget = max(left, time.Second)
}
}
return budget
}
// waitLog waits until the log holds want, then returns the log.
func waitLog(t *testing.T, l *lockedLog, want string) string {
t.Helper()
deadline := time.Now().Add(2 * time.Second)
deadline := time.Now().Add(eventBudget(t))
for !strings.Contains(l.String(), want) {
if time.Now().After(deadline) {
t.Fatalf("log never held %q:\n%s", want, l.String())
@@ -73,7 +86,7 @@ next:
func TestChunkAuthorityWaitLogsTheWaitTheAttachAndTheEnd(t *testing.T) {
logs := &lockedLog{}
captureWriteLogs(t, logs)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), eventBudget(t))
defer cancel()
v := &arrivingAssignment{seen: make(chan struct{}), assigned: make(chan struct{})}
cfg := durable.ProviderConfig{Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), NumBlocks: 64, BlockSize: 4096, ChunkBlocks: 4}