test(19.7-09): TestSessionReaper tolerates a transient store read on a loaded host

A reaper pass that cannot read the store keeps the copy by design, so the
Redis case reaps until the copy is gone and still requires exactly one
close per instance; both copies are asserted before the expiry.
This commit is contained in:
2026-10-23 18:34:46 +02:00
parent 0aa48ae6c4
commit fda46466c7

View File

@@ -124,16 +124,28 @@ func TestSessionReaper(t *testing.T) {
if n := b.pier().ReapNow(ctx); n != 0 {
t.Fatalf("B reaped a session A kept alive (%d closed)", n)
}
if n := b.pier().LocalSessions(); n != 1 {
t.Fatalf("B local sessions while the record lives = %d, want 1", n)
if na, nb := a.pier().LocalSessions(), b.pier().LocalSessions(); na != 1 || nb != 1 {
t.Fatalf("local sessions while the record lives: A %d, B %d, want 1 and 1", na, nb)
}
mr.FastForward(31 * time.Minute)
if n := b.pier().ReapNow(ctx); n != 1 {
t.Fatalf("B reaped %d sessions after the record expired, want 1", n)
}
if n := a.pier().ReapNow(ctx); n != 1 {
t.Fatalf("A reaped %d sessions after the record expired, want 1", n)
// A pass that cannot read the store keeps the copy (asserted below),
// so a loaded host may need a second pass; the copy is reaped once.
reapAll := func(name string, in *instance) {
t.Helper()
closed := 0
deadline := time.Now().Add(5 * time.Second)
for in.pier().LocalSessions() != 0 {
if time.Now().After(deadline) {
t.Fatalf("%s still holds %d copies after the record expired", name, in.pier().LocalSessions())
}
closed += in.pier().ReapNow(ctx)
}
if closed != 1 {
t.Fatalf("%s reaped %d sessions after the record expired, want 1", name, closed)
}
}
reapAll("B", b)
reapAll("A", a)
if a.pier().LocalSessions() != 0 || b.pier().LocalSessions() != 0 {
t.Fatalf("copies left: A %d, B %d", a.pier().LocalSessions(), b.pier().LocalSessions())
}