pytests: make sure test plugin `misc_notifications.py` exits fast
What changed, and why it matters
This commit fixes a test-only plugin used during automated testing. It does not change production code, user-facing behavior, or any security-sensitive logic. The plugin now exits quickly when the underlying lightning daemon refuses connections during shutdown, preventing test teardown timeouts.
No security action required. Treat as routine test maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies tests/plugins/misc_notifications.py, a pytest helper plugin. A prior change altered how lightningd rejects RPC calls during shutdown, causing a ConnectionRefusedError that was never caught. The plugin previously caught RpcError with code -5 (‘lightningd is shutting down’) and used pytest.raises inside the plugin. The patch removes the RpcError/pytest handling and instead catches ConnectionRefusedError, logs it, and exits. This is purely a test infrastructure reliability fix.
Changed components
tests/plugins/misc_notifications.pyInspect captured patch +5 / −10
diff --git a/tests/plugins/misc_notifications.py b/tests/plugins/misc_notifications.py
index f11b4da0..9180ce7d 100755
--- a/tests/plugins/misc_notifications.py
+++ b/tests/plugins/misc_notifications.py
@@ -2,9 +2,8 @@
"""Plugin to be used to test miscellaneous notifications.
"""
-from pyln.client import Plugin, RpcError
+from pyln.client import Plugin
import sys
-import pytest
plugin = Plugin()
@@ -36,14 +35,10 @@ def shutdown(plugin, **kwargs):
plugin.rpc.getinfo()
plugin.rpc.datastore(key='test', string='Allowed', mode="create-or-append")
plugin.log("via plugin stop, datastore success")
- except RpcError as e:
- if e.error == {'code': -5, 'message': 'lightningd is shutting down'}:
- # JSON RPC is disabled by now, but can do logging
- with pytest.raises(RpcError, match=r'-5.*lightningd is shutting down'):
- plugin.rpc.datastore(key='test', string='Not allowed', mode="create-or-append")
- plugin.log("via lightningd shutdown, datastore failed")
- else:
- raise
+ except ConnectionRefusedError as e:
+ # lightningd shutdown, refusing RPC calls
+ plugin.log(str(e))
+ sys.exit(0)
sys.exit(0)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.