hostlimit: test, two more ticket waits bounded by their property

- TestStalledEarlierTicketIsSkipped: instead of passing within 700 ms of
  the start, no attempt passes before the skip time and the first attempt
  begun after it passes (a 50 ms allowance for the skip judge's clock);
  the attempts' start times are printed. A loaded host's late polls no
  longer fail it (1.155 s seen on CI).
- TestUrgentProceedsPastAStalledProbe: the admission runs with an outer
  bound of ten hold waits (a block behind the probe would never return)
  and must take at least its hold wait, instead of at most hold wait +
  300 ms (1.153 s seen on CI).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-12-01 18:56:06 -08:00
1 parent bf9cec70ec
commit 7f26eded1b
1 file changed
+42 -11
+42 -11
View File
@@ -106,7 +106,8 @@ func TestDeadEarlierTicketIsRemoved(t *testing.T) {
func TestStalledEarlierTicketIsSkipped(t *testing.T) {
c := testConfig(t)
a, b := newTest(t, c), newTest(t, c)
b.testSkipAfter = 300 * time.Millisecond
const skip = 300 * time.Millisecond
b.testSkipAfter = skip
now := HostNow()
stalled, _ := a.TakeTicket(now - 2e9)
defer stalled.Close()
@@ -115,22 +116,34 @@ func TestStalledEarlierTicketIsSkipped(t *testing.T) {
start := time.Now()
var id uint64
var err error
var refused []time.Duration // when each refused attempt began, from the first
var passedAt time.Duration
for {
at := time.Since(start)
if id, err = admitWith(b, late); err == nil {
passedAt = at
break
}
if !errors.Is(err, ErrNotHead) {
t.Fatalf("refusal: %v", err)
}
refused = append(refused, at.Round(time.Millisecond))
if time.Since(start) > 3*time.Second {
t.Fatal("never passed the stalled ticket")
}
time.Sleep(20 * time.Millisecond)
}
el := time.Since(start)
b.Release(id)
if el < 300*time.Millisecond || el > 700*time.Millisecond {
t.Fatalf("passed the stalled ticket after %s; want the skip time plus a poll", el)
// The property, independent of how late a loaded host runs the polls:
// no attempt passes before the skip time, and the first attempt that
// begins after it passes (a small allowance for the skip judge's own
// clock); the attempts' start times are printed on failure.
const judge = 50 * time.Millisecond
if passedAt < skip {
t.Fatalf("passed the stalled ticket at %s, before the skip time %s (refused at %v)", passedAt.Round(time.Millisecond), skip, refused)
}
if n := len(refused); n > 0 && refused[n-1] >= skip+judge {
t.Fatalf("an attempt begun at %s, after the skip time %s, was refused (refused at %v, passed at %s)", refused[n-1], skip, refused, passedAt.Round(time.Millisecond))
}
if late.Skipped() != 1 {
t.Fatalf("skipped %d tickets", late.Skipped())
@@ -211,14 +224,32 @@ func TestUrgentProceedsPastAStalledProbe(t *testing.T) {
t.Fatal(err)
}
start := time.Now()
id, err := l.Acquire(context.Background(), Urgent, nil)
if err != nil {
t.Fatalf("urgent admission behind a stalled probe: %v", err)
type admitted struct {
id uint64
err error
el time.Duration
}
el := time.Since(start)
l.Release(id)
if el < urgentHoldWait || el > urgentHoldWait+300*time.Millisecond {
t.Fatalf("urgent admission took %s; want about %s", el, urgentHoldWait)
got := make(chan admitted, 1)
go func() {
id, err := l.Acquire(context.Background(), Urgent, nil)
got <- admitted{id, err, time.Since(start)}
}()
// Blocked behind the stalled probe, the admission would not return while
// the probe is held; bounded by its hold wait, it returns after about
// urgentHoldWait. The outer bound is ten hold waits, so a loaded host's
// scheduling does not fail it, while a block still does.
var a admitted
select {
case a = <-got:
case <-time.After(10 * urgentHoldWait):
t.Fatalf("urgent admission still waiting %s behind a stalled probe; want about %s", 10*urgentHoldWait, urgentHoldWait)
}
if a.err != nil {
t.Fatalf("urgent admission behind a stalled probe: %v", a.err)
}
l.Release(a.id)
if a.el < urgentHoldWait {
t.Fatalf("urgent admission took %s, less than its hold wait %s", a.el, urgentHoldWait)
}
if st := l.Snapshot().(Stats); st.UrgentPendingUnheld != 1 {
t.Fatalf("UrgentPendingUnheld = %d", st.UrgentPendingUnheld)