Tests if plugin rescan restarts modified plugins
(node_factory)
| 3098 | |
| 3099 | |
| 3100 | def 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 |
| 3105 | from pyln.client import Plugin |
| 3106 | import time |
| 3107 | plugin = Plugin() |
| 3108 | @plugin.init() |
| 3109 | def init(options, configuration, plugin): |
| 3110 | plugin.log("test_restart_on_update %s") |
| 3111 | plugin.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 | |
| 3149 | def test_plugin_shutdown(node_factory): |
nothing calls this directly
no test coverage detected