fix(session): report is_alive from the driver's own session
driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 19s
driver / types (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m3s
driver / lowest (pull_request) Successful in 34s
driver / test (3.13) (pull_request) Successful in 1m9s
driver / build (pull_request) Successful in 31s
driver / security (pull_request) Successful in 1m12s
CI / driver (pull_request) Successful in 2m53s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 19s
driver / types (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m3s
driver / lowest (pull_request) Successful in 34s
driver / test (3.13) (pull_request) Successful in 1m9s
driver / build (pull_request) Successful in 31s
driver / security (pull_request) Successful in 1m12s
CI / driver (pull_request) Successful in 2m53s
driver / publish (pull_request) Skipped
is_alive() opened a TCP connection to the gateway whether or not the driver was opened, and after close() too. NAPALM's __del__ asks it of every collected driver, so each one connected once more and could stall for up to five seconds. Without an open session it now answers False and connects nowhere; with one, it reports whether the gateway still answers on its port. Closes #19
This commit is contained in:
1 parent
5f0c7c76b3
commit
e5ce4e32b1
5 files changed
+74
-5
No files matched your search
+5
-3
@@ -44,9 +44,9 @@ MOCK_LOGIN_RESPONSE = {
|
||||
def _offline(driver: ZyxelVMGDriver) -> ZyxelVMGDriver:
|
||||
"""*driver*, with an is_alive() that opens no socket (#17).
|
||||
|
||||
NAPALM's ``__del__`` asks ``is_alive()``, and this driver's ``is_alive()`` connects
|
||||
to the gateway whether or not the driver was opened or closed. The tests of
|
||||
``is_alive()`` itself call the class's method.
|
||||
NAPALM's ``__del__`` asks ``is_alive()``, which connects to the gateway while the
|
||||
driver has a session; many tests give it a mock one and never close it. The tests
|
||||
of ``is_alive()`` itself call the class's method (and ``tests/test_is_alive.py``).
|
||||
"""
|
||||
driver.is_alive = lambda: {"is_alive": False} # type: ignore[method-assign]
|
||||
return driver
|
||||
@@ -163,11 +163,13 @@ class TestZyxelVMGDriver:
|
||||
assert self.driver._sessionkey is None
|
||||
|
||||
def test_is_alive(self):
|
||||
self._setup_mocked_http()
|
||||
with patch("socket.create_connection") as mock_conn:
|
||||
mock_conn.return_value.__enter__.return_value = MagicMock()
|
||||
assert ZyxelVMGDriver.is_alive(self.driver)["is_alive"] is True
|
||||
|
||||
def test_is_alive_fail(self):
|
||||
self._setup_mocked_http()
|
||||
with patch("socket.create_connection") as mock_conn:
|
||||
mock_conn.side_effect = OSError("refused")
|
||||
assert ZyxelVMGDriver.is_alive(self.driver)["is_alive"] is False
|
||||
|
||||
Reference in new issue
Block a user