fix: attach() closes executor on failure; guard session adoption

This commit is contained in:
Mathew Sir Guest the best
2026-07-07 22:35:44 -06:00
parent 3cec3f647b
commit 14281a0774
3 changed files with 60 additions and 16 deletions
+15
View File
@@ -5,6 +5,8 @@ from wabot.hosts import ReattachingRemote, attach, build_options
class TestReattachingRemote:
def test_adopts_session_id_without_creating_a_session(self):
# constructing against a closed port (127.0.0.1:1) proves no HTTP happens
# until the first command
driver = ReattachingRemote(
"http://127.0.0.1:1", "saved-session-id", options=build_options("chromium")
)
@@ -39,3 +41,16 @@ class TestAttach:
def test_returns_none_when_server_is_unreachable(self):
# no server on port 1: connection refused is immediate; attach must not raise
assert attach("http://127.0.0.1:1", "sid", "chromium") is None
def test_dead_session_closes_executor(self, monkeypatch):
from selenium.webdriver.remote.remote_connection import RemoteConnection
closed = []
monkeypatch.setattr(RemoteConnection, "close", lambda self: closed.append(1))
def boom(self):
raise WebDriverException("invalid session id")
monkeypatch.setattr(ReattachingRemote, "current_url", property(boom))
assert attach("http://127.0.0.1:1", "sid", "chromium") is None
assert closed == [1] # executor was closed, not leaked