Make TestIdleCleanupKeepsActiveUser independent of timing (closes #181)
check / check (push) Waiting to run

The test slept 500 ms, had one user send PING, and then asked for sessions last seen before the current time minus 500 ms. On a loaded host the PONG could arrive more than 500 ms later, so the active user counted as idle and the build went red. The code was right: activity is recorded before the reply and the stored time keeps nanoseconds. The test now reads the clock once after both users register and before the PING, and uses that as the cutoff, so the result follows from the order of events.

Judgement call: the test relies on the wall clock not stepping backwards between the cutoff and the PING.

Model: opus-5-5
This commit was merged in pull request #182.
This commit is contained in:
2026-10-21 13:06:01 +02:00
parent 3cbd7554e2
commit d539b4c558
+6 -4
View File
@@ -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)