Files
seaweedfs/seaweed-block/core/hostlimit/yield_test.go
T
pingqiuandClaude Opus 5.5 62ee69b0e2 hostlimit, storage, durable: red tests, a long cut yields its slot to a waiter
Seams: Config.YieldAfter (S, default 5 min), Limiter.ShouldYield (never,
for now), storage.ErrCutYielded, storage.BudgetYield, ChunkLayerStats.
CutsYielded and CutScheduleStatus.CutYields.

- TestShouldYieldOnlyAfterSWithALiveWaiter: a Normal hold yields only once
  it is S old and another process holds a live ticket; never a lone hold,
  never before S, never an urgent hold, not for a ticket judged stalled.
  Fails here: no hold ever yields.
- TestCutYieldsAtABatchBoundaryAndKeepsItsStaging: a cut whose budget asks
  it to yield ends at the next staging batch boundary with ErrCutYielded,
  counted as a yield, not a failure, publishes nothing, and its staged
  chunks are kept for the next attempt. Fails here: the cut never yields.
- TestChunkLoop_AYieldIsRetriedAtOnceAndCountedApart: a yielded attempt is
  retried at the next poll, never backed off as a failure, and status counts
  it apart. Fails here: the retry came 1.1 s later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 14:43:22 -08:00

62 lines
1.5 KiB
Go

package hostlimit
import (
"context"
"path/filepath"
"testing"
"time"
)
// A Normal hold yields only once it is S old AND another process waits (a
// live ticket in the pool): a lone hold never yields however old, a waiter
// before S changes nothing, an urgent hold never yields, and a ticket this
// process judged stalled is not a waiter.
func TestShouldYieldOnlyAfterSWithALiveWaiter(t *testing.T) {
c := testConfig(t)
c.NormalSlots = 2
c.YieldAfter = 60 * time.Millisecond
l := newTest(t, c)
waiter := newTest(t, c) // another process on the host
x, err := l.Admit(context.Background(), 1, nil)
if err != nil {
t.Fatal(err)
}
defer l.Release(x)
if l.ShouldYield(x) {
t.Fatal("a fresh hold with no waiter yields")
}
tk, err := waiter.TakeTicket(HostNow())
if err != nil {
t.Fatal(err)
}
if l.ShouldYield(x) {
t.Fatal("a hold younger than S yields to a waiter")
}
time.Sleep(80 * time.Millisecond)
if !l.ShouldYield(x) {
t.Fatal("a hold older than S does not yield to a live waiter")
}
l.markStalled(filepath.Base(tk.path))
if l.ShouldYield(x) {
t.Fatal("a ticket this process judged stalled counts as a waiter")
}
tk.Close()
if l.ShouldYield(x) {
t.Fatal("a hold older than S yields with no waiter")
}
tk2, err := waiter.TakeTicket(HostNow())
if err != nil {
t.Fatal(err)
}
defer tk2.Close()
u, err := l.Acquire(context.Background(), Urgent, nil)
if err != nil {
t.Fatal(err)
}
defer l.Release(u)
time.Sleep(80 * time.Millisecond)
if l.ShouldYield(u) {
t.Fatal("an urgent hold yields")
}
}