MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_important_plugin

Function test_important_plugin

tests/test_plugin.py:2666–2724  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

2664
2665
2666def test_important_plugin(node_factory):
2667 # Cache it here.
2668 pluginsdir = os.path.join(os.path.dirname(__file__), "plugins")
2669
2670 n = node_factory.get_node(options={"important-plugin": os.path.join(pluginsdir, "nonexistent")},
2671 may_fail=True, expect_fail=True,
2672 # Other plugins can complain as lightningd stops suddenly:
2673 broken_log='Plugin marked as important, shutting down lightningd|Reading sync lightningd: Connection reset by peer|Lost connection to the RPC socket|Plugin terminated before replying to RPC call|plugin-cln-xpay: askrene-create-layer failed with.*Unknown command',
2674 start=False)
2675
2676 n.daemon.start(wait_for_initialized=False, stderr_redir=True)
2677 # Will exit with failure code.
2678 assert n.daemon.wait() == 1
2679 assert n.daemon.is_in_stderr(r"Failed to register .*nonexistent: No such file or directory")
2680
2681 # Check we exit if the important plugin dies.
2682 n.daemon.opts['important-plugin'] = os.path.join(pluginsdir, "fail_by_itself.py")
2683
2684 n.daemon.start(wait_for_initialized=False)
2685 # Will exit with failure code.
2686 assert n.daemon.wait() == 1
2687 n.daemon.wait_for_log(r'fail_by_itself.py: Plugin marked as important, shutting down lightningd')
2688
2689 # Check if the important plugin is disabled, we run as normal.
2690 n.daemon.opts['disable-plugin'] = "fail_by_itself.py"
2691 n.daemon.start()
2692 # Make sure we can call into a plugin RPC (this is from `bcli`) even
2693 # if fail_by_itself.py is disabled.
2694 n.rpc.call("estimatefees", {})
2695 n.stop()
2696
2697 # Check if an important plugin dies later, we fail.
2698 del n.daemon.opts['disable-plugin']
2699 n.daemon.opts['important-plugin'] = os.path.join(pluginsdir, "suicidal_plugin.py")
2700
2701 n.start()
2702
2703 with pytest.raises(RpcError):
2704 n.rpc.call("die", {})
2705
2706 # Should exit with exitcode 1
2707 n.daemon.wait_for_log('suicidal_plugin.py: Plugin marked as important, shutting down lightningd')
2708 assert n.daemon.wait() == 1
2709 n.stop()
2710
2711 # Check that if a builtin plugin dies, we fail.
2712 start = n.daemon.logsearch_start
2713 n.start()
2714 # Reset logsearch_start, since this will predate message that start() looks for.
2715 n.daemon.logsearch_start = start
2716 line = n.daemon.wait_for_log(r'.*started\([0-9]*\).*plugins/pay')
2717 pidstr = re.search(r'.*started\(([0-9]*)\).*plugins/pay', line).group(1)
2718
2719 # Kill pay.
2720 os.kill(int(pidstr), signal.SIGKILL)
2721 n.daemon.wait_for_log('pay: Plugin marked as important, shutting down lightningd')
2722 # Should exit with exitcode 1
2723 assert n.daemon.wait() == 1

Callers

nothing calls this directly

Calls 9

joinMethod · 0.80
is_in_stderrMethod · 0.80
wait_for_logMethod · 0.80
killMethod · 0.80
get_nodeMethod · 0.45
startMethod · 0.45
waitMethod · 0.45
callMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected