mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
pytest: thoroughly test plugin death during startup.
We modify broken.py to be able to fail at different points, and test that during startup. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
4578748aca
commit
f4f6279b17
@ -2,18 +2,27 @@
|
||||
"""Simple plugin to test that lightningd doesnt crash if it starts a
|
||||
misbehaving plugin via RPC.
|
||||
"""
|
||||
|
||||
from pyln.client import Plugin
|
||||
import an_unexistent_module_that_will_make_me_crash
|
||||
|
||||
plugin = Plugin(dynamic=False)
|
||||
import os
|
||||
plugin = Plugin()
|
||||
crash_at = os.environ.get("BROKEN_CRASH", "before_start")
|
||||
|
||||
|
||||
@plugin.init()
|
||||
def init(options, configuration, plugin):
|
||||
plugin.log("broken.py initializing {}".format(configuration))
|
||||
# We need to actually use the import to pass source checks..
|
||||
an_unexistent_module_that_will_make_me_crash.hello()
|
||||
assert crash_at == "during_init"
|
||||
plugin.does_not_exist()
|
||||
|
||||
|
||||
@plugin.method("test_broken")
|
||||
def test_broken():
|
||||
return {}
|
||||
|
||||
|
||||
if crash_at == "before_start":
|
||||
assert False
|
||||
elif crash_at == "during_getmanifest":
|
||||
del plugin.methods['getmanifest']
|
||||
|
||||
plugin.run()
|
||||
|
@ -300,6 +300,19 @@ def test_plugin_command(node_factory):
|
||||
n.rpc.stop()
|
||||
|
||||
|
||||
@pytest.mark.xfail(strict=True)
|
||||
def test_plugin_fail_on_startup(node_factory):
|
||||
for crash in ('during_init', 'before_start', 'during_getmanifest'):
|
||||
os.environ['BROKEN_CRASH'] = crash
|
||||
n = node_factory.get_node(options={'plugin': os.path.join(os.getcwd(), "tests/plugins/broken.py")})
|
||||
# This can happen before 'Server started with public key' msg
|
||||
n.daemon.logsearch_start = 0
|
||||
n.daemon.wait_for_log('plugin-broken.py: Traceback')
|
||||
|
||||
# Make sure they don't die *after* the message!
|
||||
time.sleep(30)
|
||||
|
||||
|
||||
def test_plugin_disable(node_factory):
|
||||
"""--disable-plugin works"""
|
||||
plugin_dir = os.path.join(os.getcwd(), 'contrib/plugins')
|
||||
|
Loading…
Reference in New Issue
Block a user