fix(remote): measure the idle time of a remote session on a monotonic clock

This commit is contained in:
imSp4rky
2026-11-30 17:06:15 -07:00
parent 34a3820eb8
commit e813737506
6 changed files with 59 additions and 31 deletions
+9 -5
View File
@@ -3,7 +3,6 @@
from __future__ import annotations
import asyncio
import atexit
import contextlib
import signal
import subprocess
@@ -31,7 +30,7 @@ from tests.remote.unit.test_remote_loopback import (
from tests.remote.unit.test_remote_service_helpers import blob
from tests.remote.unit.test_session_reopen import SERVER, make_service
from tests.remote.unit.test_tunnel import wait_until
from unshackle.core import remote_channel, remote_service
from unshackle.core import remote_channel, remote_lifetime, remote_service
from unshackle.core.api import handlers, routes, session_store
from unshackle.core.api.download_manager import busy_services
from unshackle.core.api.session_store import SessionEntry
@@ -640,8 +639,13 @@ def test_the_end_does_not_wait_for_a_reopen(server: SimpleNamespace, logins: lis
@pytest.fixture
def exit_hooks(monkeypatch: pytest.MonkeyPatch) -> list[Any]:
hooks: list[Any] = []
monkeypatch.setattr(atexit, "register", hooks.append)
monkeypatch.setattr(atexit, "unregister", lambda hook: hooks.remove(hook) if hook in hooks else None)
def unregister(hook: Any) -> None:
if hook in hooks:
hooks.remove(hook)
fake = SimpleNamespace(register=hooks.append, unregister=unregister)
monkeypatch.setattr(remote_lifetime, "atexit", fake) # other modules register hooks of their own meanwhile
return hooks
@@ -994,7 +998,7 @@ def test_an_end_of_another_thread_stops_the_opening(
return {}
if at == "hook":
monkeypatch.setattr(atexit, "register", lambda hook: end() and None or exit_hooks.append(hook))
monkeypatch.setattr(remote_lifetime.atexit, "register", lambda hook: end() and None or exit_hooks.append(hook))
elif at == "create":
monkeypatch.setattr(remote_service, "launch_keys", end)
else: