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

Function test_restart_on_update

tests/test_plugin.py:3100–3146  ·  view source on GitHub ↗

Tests if plugin rescan restarts modified plugins

(node_factory)

Source from the content-addressed store, hash-verified

3098
3099
3100def test_restart_on_update(node_factory):
3101 """Tests if plugin rescan restarts modified plugins
3102 """
3103 # we need to write plugin content dynamically
3104 content = """#!/usr/bin/env python3
3105from pyln.client import Plugin
3106import time
3107plugin = Plugin()
3108@plugin.init()
3109def init(options, configuration, plugin):
3110 plugin.log("test_restart_on_update %s")
3111plugin.run()
3112 """
3113
3114 # get a node that is not started so we can put a plugin in its lightning_dir
3115 n = node_factory.get_node(start=False)
3116 if "dev-no-plugin-checksum" in n.daemon.opts:
3117 del n.daemon.opts["dev-no-plugin-checksum"]
3118
3119 lndir = n.daemon.lightning_dir
3120
3121 # write hello world plugin to lndir/plugins
3122 os.makedirs(os.path.join(lndir, 'plugins'), exist_ok=True)
3123 path = os.path.join(lndir, 'plugins', 'test_restart_on_update.py')
3124 with open(path, 'w+') as file:
3125 file.write(content % "1")
3126 os.chmod(path, os.stat(path).st_mode | stat.S_IEXEC)
3127
3128 # now fire up the node and wait for the plugin to print hello
3129 n.daemon.start()
3130 n.daemon.logsearch_start = 0
3131 n.daemon.wait_for_log(r"test_restart_on_update 1")
3132
3133 # a rescan should not yet reload the plugin on the same file
3134 n.rpc.plugin_rescan()
3135 assert not n.daemon.is_in_log(r"Plugin changed, needs restart.")
3136
3137 # modify the file
3138 with open(path, 'w+') as file:
3139 file.write(content % "2")
3140 os.chmod(path, os.stat(path).st_mode | stat.S_IEXEC)
3141
3142 # rescan and check
3143 n.rpc.plugin_rescan()
3144 n.daemon.wait_for_log(r"Plugin changed, needs restart.")
3145 n.daemon.wait_for_log(r"test_restart_on_update 2")
3146 n.stop()
3147
3148
3149def test_plugin_shutdown(node_factory):

Callers

nothing calls this directly

Calls 8

joinMethod · 0.80
wait_for_logMethod · 0.80
plugin_rescanMethod · 0.80
is_in_logMethod · 0.80
get_nodeMethod · 0.45
writeMethod · 0.45
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected