test(qa): synchronize parser descendant timeout fixture

This commit is contained in:
cesnimda
2026-10-22 21:42:34 +02:00
parent 8cfc684c64
commit 25a481cd57
3 changed files with 45 additions and 0 deletions
+19
View File
@@ -5,6 +5,7 @@ import os
import subprocess
import sys
import textwrap
import time
import zipfile
from pathlib import Path
@@ -759,6 +760,7 @@ def test_parser_timeout_terminates_descendants(monkeypatch, tmp_path):
child.write_text(textwrap.dedent(f"""
import subprocess, sys, time
from pathlib import Path
time.sleep(0.3)
descendant = subprocess.Popen([sys.executable, '-c', 'import time; time.sleep(30)'])
Path({str(pid_path)!r}).write_text(str(descendant.pid), encoding='ascii')
time.sleep(30)
@@ -766,6 +768,23 @@ def test_parser_timeout_terminates_descendants(monkeypatch, tmp_path):
monkeypatch.setattr(module, "PARSER_CHILD_PATH", child)
monkeypatch.setattr(module, "PARSER_TIMEOUT_SECONDS", 0.2)
# Start the deadline only after this fixture has a descendant to terminate.
original_popen = subprocess.Popen
def ready_parser(*args, **kwargs):
process = original_popen(*args, **kwargs)
if len(args[0]) > 1 and args[0][1] == str(child):
deadline = time.monotonic() + 5
while not pid_path.exists() and process.poll() is None and time.monotonic() < deadline:
time.sleep(0.01)
if not pid_path.exists():
module._terminate_parser_process(process)
process.wait(timeout=5)
raise AssertionError("Parser fixture did not create its descendant")
return process
monkeypatch.setattr(module.subprocess, "Popen", ready_parser)
try:
module._run_parser_child(".txt", b"safe")
except module.HTTPException as exc: