perf(process): wake waiters on background completion (#45831)
This commit is contained in:
@@ -5,6 +5,7 @@ import os
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
@@ -266,6 +267,31 @@ class TestOrphanedPipeReconciliation:
|
||||
except (ProcessLookupError, PermissionError):
|
||||
pass
|
||||
|
||||
def test_wait_wakes_when_session_moves_to_finished(self, registry):
|
||||
"""wait() should not sleep for the old 1s polling tick after exit."""
|
||||
s = _make_session(sid="proc_wait_event", output="done")
|
||||
registry._running[s.id] = s
|
||||
|
||||
def finish_later():
|
||||
time.sleep(0.05)
|
||||
s.exited = True
|
||||
s.exit_code = 0
|
||||
with patch.object(registry, "_write_checkpoint"):
|
||||
registry._move_to_finished(s)
|
||||
|
||||
t = threading.Thread(target=finish_later)
|
||||
t.start()
|
||||
start = time.monotonic()
|
||||
try:
|
||||
result = registry.wait(s.id, timeout=5)
|
||||
finally:
|
||||
t.join(timeout=1)
|
||||
elapsed = time.monotonic() - start
|
||||
|
||||
assert result["status"] == "exited", result
|
||||
assert result["exit_code"] == 0
|
||||
assert elapsed < 0.3, f"wait() should wake on completion; took {elapsed:.3f}s"
|
||||
|
||||
|
||||
# =========================================================================
|
||||
# Read log
|
||||
|
||||
Reference in New Issue
Block a user