Skip to content

Commit ddb4f28

Browse files
xndcnbizfsc
andcommitted
test: Add regression tests for notifier lifecycle
Add tests to verify that: - connect() does not recreate an existing notifier - disconnect() releases the notifier - disconnect() releases the notifier even when check() raises Co-authored-by: Frieder Schüler <frieder.schueler@bizerba.com>
1 parent 8f4363a commit ddb4f28

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

test/test_network.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,34 @@ def wait_for_periodicity():
285285
if msg is not None:
286286
self.assertIsNone(bus.recv(PERIOD))
287287

288+
def test_network_connect_does_not_recreate_notifier(self):
289+
self.network.connect(interface="virtual")
290+
self.addCleanup(self.network.disconnect)
291+
notifier1 = self.network.notifier
292+
self.assertIsNotNone(notifier1)
293+
# Calling connect() again should reuse the existing notifier
294+
self.network.connect(interface="virtual")
295+
self.assertIs(self.network.notifier, notifier1)
296+
297+
def test_network_disconnect_releases_notifier(self):
298+
self.network.connect(interface="virtual")
299+
self.assertIsNotNone(self.network.notifier)
300+
self.network.disconnect()
301+
self.assertIsNone(self.network.notifier)
302+
303+
def test_network_disconnect_releases_notifier_on_exception(self):
304+
self.network.connect(interface="virtual")
305+
306+
class Custom(Exception):
307+
pass
308+
309+
self.network.notifier.exception = Custom("fake")
310+
with self.assertRaises(Custom):
311+
with self.assertLogs(level=logging.ERROR):
312+
self.network.disconnect()
313+
# Notifier must be released even when check() raises
314+
self.assertIsNone(self.network.notifier)
315+
288316

289317
class TestScanner(unittest.TestCase):
290318
TIMEOUT = 0.1

0 commit comments

Comments
 (0)