mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-09-03 15:20:42 +02:00
test: harden handshake tests against timing and stale socket files
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)]
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user