From fda46466c7a926577d13f91030833edc64cea3bb Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Fri, 23 Oct 2026 18:34:46 +0200 Subject: [PATCH] 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. --- modules/pier/reaper_test.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/modules/pier/reaper_test.go b/modules/pier/reaper_test.go index 597babcb..01e19897 100644 --- a/modules/pier/reaper_test.go +++ b/modules/pier/reaper_test.go @@ -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()) }