File size: 889 Bytes
af4851b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from pathlib import Path

from backend.session_store import SessionStore


def test_session_store_creates_isolated_session_dirs(tmp_path: Path) -> None:
    store = SessionStore(root=tmp_path, ttl_seconds=60)

    first = store.ensure_session("session-a")
    second = store.ensure_session("session-b")

    assert first.session_id == "session-a"
    assert second.session_id == "session-b"
    assert first.root.exists()
    assert second.root.exists()
    assert first.root != second.root


def test_session_store_prunes_expired_sessions(tmp_path: Path) -> None:
    store = SessionStore(root=tmp_path, ttl_seconds=0)
    session = store.ensure_session("session-a")
    marker = session.root / "marker.txt"
    marker.write_text("old", encoding="utf-8")

    removed = store.cleanup_expired(now=store._now() + 1)

    assert removed == ["session-a"]
    assert not session.root.exists()