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

Function test_important_plugin

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

Source from the content-addressed store, hash-verified

2104
2105
2106def test_important_plugin(node_factory):
2107 # Cache it here.
2108 pluginsdir = os.path.join(os.path.dirname(__file__), "plugins")
2109
2110 n = node_factory.get_node(options={"important-plugin": os.path.join(pluginsdir, "nonexistent")},
2111 may_fail=True, expect_fail=True,
2112 allow_broken_log=True, start=False)
2113
2114 n.daemon.start(wait_for_initialized=False, stderr_redir=True)
2115 # Will exit with failure code.
2116 assert n.daemon.wait() == 1
2117 assert n.daemon.is_in_stderr(r"Failed to register .*nonexistent: No such file or directory")
2118
2119 # Check we exit if the important plugin dies.
2120 n.daemon.opts['important-plugin'] = os.path.join(pluginsdir, "fail_by_itself.py")
2121
2122 n.daemon.start(wait_for_initialized=False)
2123 # Will exit with failure code.
2124 assert n.daemon.wait() == 1
2125 n.daemon.wait_for_log(r'fail_by_itself.py: Plugin marked as important, shutting down lightningd')
2126
2127 # Check if the important plugin is disabled, we run as normal.
2128 n.daemon.opts['disable-plugin'] = "fail_by_itself.py"
2129 n.daemon.start()
2130 # Make sure we can call into a plugin RPC (this is from `bcli`) even
2131 # if fail_by_itself.py is disabled.
2132 n.rpc.call("estimatefees", {})
2133 n.stop()
2134
2135 # Check if an important plugin dies later, we fail.
2136 del n.daemon.opts['disable-plugin']
2137 n.daemon.opts['important-plugin'] = os.path.join(pluginsdir, "suicidal_plugin.py")
2138
2139 n.start()
2140
2141 with pytest.raises(RpcError):
2142 n.rpc.call("die", {})
2143
2144 # Should exit with exitcode 1
2145 n.daemon.wait_for_log('suicidal_plugin.py: Plugin marked as important, shutting down lightningd')
2146 assert n.daemon.wait() == 1
2147 n.stop()
2148
2149 # Check that if a builtin plugin dies, we fail.
2150 start = n.daemon.logsearch_start
2151 n.start()
2152 # Reset logsearch_start, since this will predate message that start() looks for.
2153 n.daemon.logsearch_start = start
2154 line = n.daemon.wait_for_log(r'.*started\([0-9]*\).*plugins/pay')
2155 pidstr = re.search(r'.*started\(([0-9]*)\).*plugins/pay', line).group(1)
2156
2157 # Kill pay.
2158 os.kill(int(pidstr), signal.SIGKILL)
2159 n.daemon.wait_for_log('pay: Plugin marked as important, shutting down lightningd')
2160 # Should exit with exitcode 1
2161 assert n.daemon.wait() == 1
2162 n.stop()
2163

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