Make TestIdleCleanupKeepsActiveUser independent of timing (closes #181) #182

Merged
clawbot merged 1 commits from issue-181-idle-cleanup-test into next 2026-10-21 13:06:02 +02:00
+6 -4
View File
@@ -645,8 +645,6 @@ func TestNewPingTimes(t *testing.T) {
func TestIdleCleanupKeepsActiveUser(t *testing.T) { func TestIdleCleanupKeepsActiveUser(t *testing.T) {
t.Parallel() t.Parallel()
const idleTimeout = 500 * time.Millisecond
env := newTestEnv(t) env := newTestEnv(t)
active := env.dial(t) active := env.dial(t)
@@ -655,13 +653,17 @@ func TestIdleCleanupKeepsActiveUser(t *testing.T) {
idle := env.dial(t) idle := env.dial(t)
idle.register("idle") 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") active.sendAndExpect("PING :still here", "PONG")
// The idle cleanup in internal/handlers removes exactly // The idle cleanup in internal/handlers removes exactly
// the users this returns. // the users this returns.
stale, err := env.database.GetStaleOrphanSessions( stale, err := env.database.GetStaleOrphanSessions(
t.Context(), time.Now().Add(-idleTimeout), t.Context(), cutoff,
) )
if err != nil { if err != nil {
t.Fatalf("get stale sessions: %v", err) t.Fatalf("get stale sessions: %v", err)