From 48f36904c8bac176318fe1524978d1761c71e58b Mon Sep 17 00:00:00 2001 From: ZmnSCPxj jxPCSnmZ Date: Thu, 30 Jul 2020 13:40:29 +0800 Subject: [PATCH] tests/test_plugin.py: Add test for --important-plugin. --- tests/plugins/suicidal_plugin.py | 14 ++++++++++++ tests/test_plugin.py | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 tests/plugins/suicidal_plugin.py diff --git a/tests/plugins/suicidal_plugin.py b/tests/plugins/suicidal_plugin.py new file mode 100755 index 000000000..75e58a53d --- /dev/null +++ b/tests/plugins/suicidal_plugin.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +from pyln.client import Plugin +import os + +plugin = Plugin() + + +@plugin.method("die") +def die(): + os._exit(1) + + +plugin.run() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index a8fc892c3..c857bb0d7 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1534,3 +1534,41 @@ def test_3847_repro(node_factory, bitcoind): # This call to paystatus would fail if the pay plugin crashed (it's # provided by the plugin) l1.rpc.paystatus(i1) + + +def test_important_plugin(node_factory): + # Cache it here. + pluginsdir = os.path.join(os.path.dirname(__file__), "plugins") + + # Check we fail if we cannot find the important plugin. + n = node_factory.get_node(options={"important-plugin": os.path.join(pluginsdir, "nonexistent")}, + may_fail=True, expect_fail=True, + allow_broken_log=True) + assert not n.daemon.running + assert n.daemon.is_in_stderr(r"error starting plugin '.*nonexistent'") + + # Check we exit if the important plugin dies. + n = node_factory.get_node(options={"important-plugin": os.path.join(pluginsdir, "fail_by_itself.py")}, + may_fail=True, expect_fail=True, + allow_broken_log=True) + + n.daemon.wait_for_log('fail_by_itself.py: Plugin marked as important, shutting down lightningd') + wait_for(lambda: not n.daemon.running) + + # Check if the important plugin is disabled, we run as normal. + n = node_factory.get_node(options=OrderedDict([("important-plugin", os.path.join(pluginsdir, "fail_by_itself.py")), + ("disable-plugin", "fail_by_itself.py")])) + # Make sure we can call into a plugin RPC (this is from `bcli`) even + # if fail_by_itself.py is disabled. + n.rpc.call("estimatefees", {}) + # Make sure we are still running. + assert n.daemon.running + n.stop() + + # Check if an important plugin dies later, we fail. + n = node_factory.get_node(options={"important-plugin": os.path.join(pluginsdir, "suicidal_plugin.py")}, + may_fail=True, allow_broken_log=True) + with pytest.raises(RpcError): + n.rpc.call("die", {}) + n.daemon.wait_for_log('suicidal_plugin.py: Plugin marked as important, shutting down lightningd') + wait_for(lambda: not n.daemon.running)