Skip to content

Commit 027ac5a

Browse files
fix: server restart hanging
1 parent 140d31f commit 027ac5a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

pytest_netconf/netconfserver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def start(self) -> None:
231231
OSError: If the server fails to bind to the specified port.
232232
"""
233233
self.running = True
234+
self._hello_sent = False # reset in case of restart
234235
self._bind_socket()
235236
self._thread = threading.Thread(target=self._run)
236237
self._thread.start()

tests/integration/test_ncclient.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,30 @@ def test_when_connecting_using_username_and_wrong_key_then_authentication_fails(
292292
...
293293

294294
# THEN expect error
295-
assert error
295+
assert error
296+
297+
298+
def test_when_server_restarted_then_connection_passes(netconf_server: NetconfServer):
299+
# GIVEN initial connection to server
300+
with manager.connect(
301+
host="localhost",
302+
port=8830,
303+
username="admin",
304+
password="admin",
305+
hostkey_verify=False,
306+
) as m:
307+
assert m.connected
308+
309+
# WHEN server is stopped and then started again
310+
netconf_server.stop()
311+
netconf_server.start()
312+
313+
# THEN expect reconnection to succeed
314+
with manager.connect(
315+
host="localhost",
316+
port=8830,
317+
username="admin",
318+
password="admin",
319+
hostkey_verify=False,
320+
) as m:
321+
assert m.connected

0 commit comments

Comments
 (0)