From 7291351466720ccbad2dfb93a6da516771af82ce Mon Sep 17 00:00:00 2001 From: sneak Date: Wed, 21 Oct 2026 04:52:00 +0000 Subject: [PATCH] Make TestIdleCleanupKeepsActiveUser independent of timing (closes #181) The test slept 500 ms, had active send PING, then asked for sessions last seen before now minus 500 ms. On a loaded host the PONG can take more than 500 ms to arrive, which puts active's last-seen time before that cutoff. The code is right: it records the time before it replies, to the nanosecond. The test now takes the cutoff after both users register and before active's PING, so the result follows from the order of events alone. Model: opus-5-5 --- internal/ircserver/server_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/ircserver/server_test.go b/internal/ircserver/server_test.go index 3b7eabf..a530b36 100644 --- a/internal/ircserver/server_test.go +++ b/internal/ircserver/server_test.go @@ -645,8 +645,6 @@ func TestNewPingTimes(t *testing.T) { func TestIdleCleanupKeepsActiveUser(t *testing.T) { t.Parallel() - const idleTimeout = 500 * time.Millisecond - env := newTestEnv(t) active := env.dial(t) @@ -655,13 +653,17 @@ func TestIdleCleanupKeepsActiveUser(t *testing.T) { idle := env.dial(t) idle.register("idle") - time.Sleep(idleTimeout) + // Both users were last seen before cutoff, and only active + // sends a command after it, so the result does not depend + // on how long the PONG takes to arrive. + cutoff := time.Now() + active.sendAndExpect("PING :still here", "PONG") // The idle cleanup in internal/handlers removes exactly // the users this returns. stale, err := env.database.GetStaleOrphanSessions( - t.Context(), time.Now().Add(-idleTimeout), + t.Context(), cutoff, ) if err != nil { t.Fatalf("get stale sessions: %v", err) -- 2.54.0