Pty.wait_for_bytes bricht ab, wenn der Monitor beendet ist

Die Wartefunktion endete nur bei genügend Bytes oder nach TIMEOUT (15 s);
der Lesethread der Pty bekommt kein EIO, solange die eigene Slave-Seite
offen ist. Beendete sich der Monitor gleich beim Start (ungültige
Konfiguration, Importfehler, Absturz), saß
test_echte_schnittstelle_bytestrom_… trotzdem 15 s je Fall ab, mit
beiden Parametern 30 s (gemessen mit der Mutation MIN_INTERVAL >= → >).

Der im Review vorgeschlagene Tausch der beiden Wartevorgänge (erst
„Display verbunden“, dann die Bytes) passt nicht mehr: Die Zeile kommt
seit dem Ausfall-Commit erst nach dem ersten vollständigen Bild, im Fall
mitten-im-ersten-bild also nie vor der Pause. Stattdessen bekommt
wait_for_bytes den Prozess und prüft in Abständen von 0,1 s, ob er noch
läuft. Mit derselben Mutation scheitern beide Fälle jetzt nach je 0,2 s,
die Meldung zeigt die ERROR-Zeile des Monitors.

Test: wait_for_bytes gibt bei einem sofort beendeten Prozess schnell
False zurück.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main
AmiPoke 3 weeks ago
parent f15a763a17
commit a82517ee1c
  1. 22
      tests/test_cli.py

@ -218,9 +218,17 @@ class Pty:
self._data += chunk self._data += chunk
self._cond.notify_all() self._cond.notify_all()
def wait_for_bytes(self, count: int, timeout: float = TIMEOUT) -> bool: def wait_for_bytes(self, count: int, proc: subprocess.Popen, timeout: float = TIMEOUT) -> bool:
"""Wartet auf count Bytes, gibt aber auf, sobald proc beendet ist: der Lesethread bekommt kein EIO,
solange die eigene Slave-Seite offen ist, und sähe das Ende nie."""
deadline = time.monotonic() + timeout
with self._cond: with self._cond:
return self._cond.wait_for(lambda: len(self._data) >= count, timeout) while len(self._data) < count:
remaining = deadline - time.monotonic()
if remaining <= 0 or proc.poll() is not None:
return False
self._cond.wait(min(remaining, 0.1))
return True
def resume(self) -> None: def resume(self) -> None:
with self._cond: with self._cond:
@ -243,6 +251,14 @@ class Pty:
return bytes(self._data) return bytes(self._data)
def test_warten_auf_bytes_endet_mit_dem_prozess():
# sonst säße ein Test, dessen Monitor gleich beim Start scheitert, die vollen TIMEOUT je Fall ab
with Pty() as pty, subprocess.Popen([sys.executable, "-c", ""]) as proc:
start = time.monotonic()
assert not pty.wait_for_bytes(1, proc)
assert time.monotonic() - start < STOP_TIMEOUT
def assert_port_locked(port: str) -> None: def assert_port_locked(port: str) -> None:
"""Der Monitor hält die Schnittstelle exklusiv (pyserial nutzt dafür flock).""" """Der Monitor hält die Schnittstelle exklusiv (pyserial nutzt dafür flock)."""
fd = os.open(port, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK) fd = os.open(port, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
@ -271,7 +287,7 @@ def test_echte_schnittstelle_bytestrom_geht_beim_beenden_exakt_auf(tmp_path, mid
with Pty(pause_at) as pty: with Pty(pause_at) as pty:
config = write_config(tmp_path, pty.port, "memory_interval = 0.5\n") config = write_config(tmp_path, pty.port, "memory_interval = 0.5\n")
with MonitorProcess(config) as monitor: with MonitorProcess(config) as monitor:
assert pty.wait_for_bytes(pause_at or CONNECT + FULL_FRAME), monitor.output assert pty.wait_for_bytes(pause_at or CONNECT + FULL_FRAME, monitor.proc), monitor.output
if mid_transfer: if mid_transfer:
assert "Display verbunden" not in monitor.output # erst nach dem ersten vollständigen Bild assert "Display verbunden" not in monitor.output # erst nach dem ersten vollständigen Bild
else: else:

Loading…
Cancel
Save