test: harden handshake tests against timing and stale socket files

This commit is contained in:
2026-08-25 13:45:27 +02:00
committed by wakonig_k
parent 99349da304
commit ea222a06ac
4 changed files with 14 additions and 3 deletions
+6
View File
@@ -23,6 +23,12 @@ class _Server:
self.path = path
self._srv = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self._srv.settimeout(2.0)
# A crashed previous run (with pid reuse) can leave the socket file behind,
# which would make bind() fail with "Address already in use".
try:
os.unlink(path)
except FileNotFoundError:
pass
self._srv.bind(path)
self._srv.listen(1)
self._conn: socket.socket | None = None
+1 -1
View File
@@ -142,7 +142,7 @@ def test_launch_window_notifies_launcher_ready(qtbot, bec_launch_window, monkeyp
qtbot.addWidget(window)
window.show()
bec_launch_window._notify_launcher_ready(window)
qtbot.wait(10)
qtbot.waitUntil(lambda: calls == [("bec-gui-server", window)], timeout=1000)
assert calls == [("bec-gui-server", window)]
+6
View File
@@ -26,6 +26,12 @@ def test_notify_launcher_ready_sends_ready(monkeypatch):
path = _short_socket_path()
srv = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
srv.settimeout(2.0)
# A crashed previous run (with pid reuse) can leave the socket file behind,
# which would make bind() fail with "Address already in use".
try:
os.unlink(path)
except FileNotFoundError:
pass
srv.bind(path)
srv.listen(1)
try:
+1 -2
View File
@@ -88,8 +88,7 @@ def test_main_app_notifies_launcher_ready_after_show(qtbot, mocked_client, monke
qtbot.addWidget(app)
app.show()
qtbot.waitExposed(app)
qtbot.wait(10)
qtbot.waitUntil(lambda: calls == [("bec-app", app)], timeout=1000)
assert calls == [("bec-app", app)]