storage: test: the slow-extent red tolerates a slow fsync

TestWALStoreV3SlowExtentKeepsReclaimMoving flaked on a busy Windows
host: a single slow fsync pushed one bounded cycle past its 500 ms
admission budget (attempts of 500-577 ms, against cycles whose writes
take about 77 ms). The slow disk is now 5 ms per extent write and the
budget half a whole-map cycle from the measured sleep (about 1.2 s): a
bounded cycle (about 160 ms of writes) leaves room for a slow fsync,
and a whole-map cycle (about 2.4 s) still outlasts the budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-12-02 05:51:03 -08:00
1 parent b6ccca62f9
commit 4c4e753b61
1 file changed
+29 -7
@@ -6,6 +6,7 @@ import (
"math"
"math/rand"
"path/filepath"
"sort"
"testing"
"time"
)
@@ -181,11 +182,11 @@ func TestWALStoreV3DrainHeldIsTheFlusherPhase(t *testing.T) {
}
// A dense image written as single 4 KiB writes in random order, three
// WALs' worth, on a slow disk (every extent write takes 2 ms), with a 500 ms admission
// budget. A whole-map cycle (about 480 entries, about 1 s) frees nothing
// until it ends, so a write times out waiting for space; bounded cycles free
// space every sixteenth of the WAL, and no write times out while reclaim
// moves. The guest sees a slow disk, not errors.
// WALs' worth, on a slow disk (every extent write takes 5 ms), with an
// admission budget of half a whole-map cycle. A whole-map cycle (about 480
// entries) frees nothing until it ends, so a write times out waiting for
// space; bounded cycles free space every sixteenth of the WAL, and no write
// times out while reclaim moves. The guest sees a slow disk, not errors.
func TestWALStoreV3SlowExtentKeepsReclaimMoving(t *testing.T) {
const walSize = 2 << 20
const count = 3 * walSize / 4096
@@ -195,8 +196,17 @@ func TestWALStoreV3SlowExtentKeepsReclaimMoving(t *testing.T) {
t.Fatal(err)
}
t.Cleanup(func() { _ = s.Close() })
s.admissionTimeout = 500 * time.Millisecond
s.flusher.beforeExtentWriteForTest = func() { time.Sleep(2 * time.Millisecond) }
// The slow disk is a 5 ms sleep per extent write. The admission budget is
// half a whole-map cycle (about 480 records), from the sleep as measured
// on this host: a whole-map cycle still outlasts it (the red), while a
// bounded cycle (a sixteenth of this WAL, about 32 records) leaves room
// for a slow fsync on a busy host (the budget is about 1.2 s, the bounded
// cycle's writes about 160 ms).
const delay = 5 * time.Millisecond
sleep := measuredSleep(delay)
s.admissionTimeout = 240 * sleep
t.Logf("measured sleep %v: admission budget %v", sleep, s.admissionTimeout)
s.flusher.beforeExtentWriteForTest = func() { time.Sleep(delay) }
lbas := rand.New(rand.NewSource(1)).Perm(count)
start := time.Now()
busy := 0
@@ -528,3 +538,15 @@ func TestWALStoreV3HeldDrainEndsInTheProductionDrain(t *testing.T) {
}
}
}
// measuredSleep is the median time a sleep of d actually takes on this host.
func measuredSleep(d time.Duration) time.Duration {
var got [9]time.Duration
for i := range got {
start := time.Now()
time.Sleep(d)
got[i] = time.Since(start)
}
sort.Slice(got[:], func(i, j int) bool { return got[i] < got[j] })
return got[len(got)/2]
}