Files
plugins/autoreload/tests/test_autoreload.py
Christian Decker 63c9872ec2 autoreload: Add tests and warning when manifest changes
Rene pointed out that we were silently accepting an updated manifest despite
not actually being able to register it with `lightningd`. This meant that if
options, RPC methods, hooks or notifications get added or removed they will
not be wired in correctly.

The warning is really obnoxious and multi-line to draw the attention.

Suggested-by: Rene Pickhardt <@renepickhardt>
2020-05-18 22:44:49 +02:00

60 lines
1.8 KiB
Python

from pyln.testing.fixtures import *
import shutil
import subprocess
import time
import os
import unittest
def copy_plugin(src, directory, filename=None):
base = os.path.dirname(__file__)
src = os.path.join(base, src)
dst = os.path.join(directory, filename if filename is not None else os.path.basename(src))
shutil.copy(src, dst)
shutil.copystat(src, dst)
return dst
def test_restart_on_change(node_factory, directory):
# Copy the dummy plugin over
plugin = copy_plugin("dummy.py", directory, "plugin.py")
opts = {
'plugin': os.path.join(os.path.dirname(__file__), "..", 'autoreload.py'),
'autoreload-plugin': plugin,
}
l1 = node_factory.get_node(options=opts)
subprocess.check_call(['touch', plugin])
l1.daemon.wait_for_log(r'Detected a change in the child plugin, restarting')
@unittest.skipIf(True, "Doesn't work on travis yet")
def test_changing_manifest(node_factory, directory):
"""Change the manifest in-between restarts.
Adding an RPC method like the switch from dummy.py to dummy2.py does,
should result in an error while reloading the plugin.
"""
# Copy the dummy plugin over
plugin = copy_plugin("dummy.py", directory, "plugin.py")
plugin_path = os.path.join(os.path.dirname(__file__), "..", 'autoreload.py')
opts = {
'plugin': os.path.join(os.path.dirname(__file__), "..", 'autoreload.py'),
'autoreload-plugin': plugin,
}
l1 = node_factory.get_node(options=opts, allow_broken_log=True)
plugin = copy_plugin("dummy2.py", directory, "plugin.py")
time.sleep(10)
subprocess.check_call(['touch', plugin_path])
time.sleep(10)
subprocess.check_call(['touch', plugin_path])
l1.daemon.wait_for_log(r'Detected a change in the child plugin, restarting')
l1.daemon.wait_for_log(r'You need to restart c-lightning')