diff --git a/tests/plugins/fail_by_itself.py b/tests/plugins/fail_by_itself.py new file mode 100755 index 000000000..5023ee725 --- /dev/null +++ b/tests/plugins/fail_by_itself.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +from pyln.client import Plugin +import os +import threading +import time + +plugin = Plugin() + + +class FailThread(threading.Thread): + def __init__(self): + super().__init__() + self.start() + + def run(self): + time.sleep(1) + print("Exiting!") + os._exit(1) + + +@plugin.init() +def init(options, configuration, plugin): + FailThread() + + +@plugin.method('failcmd') +def failcmd(plugin): + pass + + +plugin.run() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index acb6b5f14..16e45f94c 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1218,3 +1218,18 @@ def test_replacement_payload(node_factory): l1.rpc.pay(inv) assert l2.daemon.wait_for_log("Attept to pay.*with wrong secret") + + +def test_plugin_fail(node_factory): + """Test that a plugin which fails (not during a command)""" + plugin = os.path.join(os.path.dirname(__file__), 'plugins/fail_by_itself.py') + l1 = node_factory.get_node(options={"plugin": plugin}) + + time.sleep(2) + # It should clean up! + assert 'failcmd' not in [h['command'] for h in l1.rpc.help()['help']] + + l1.rpc.plugin_start(plugin) + time.sleep(2) + # It should clean up! + assert 'failcmd' not in [h['command'] for h in l1.rpc.help()['help']]