mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
testing: remove test_htlc_accepted_hook_shutdown, move relevant parts
into test_plugin_shutdown The fact that plugins are kept alive untill the very end also ensures their hooks are not silently unregistered.
This commit is contained in:
committed by
Rusty Russell
parent
9b70c9d63b
commit
28816c387c
@@ -3,7 +3,6 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from pyln.client import Plugin, RpcError
|
from pyln.client import Plugin, RpcError
|
||||||
from time import sleep
|
|
||||||
import sys
|
import sys
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -30,25 +29,22 @@ def channel_state_changed(plugin, channel_state_changed, **kwargs):
|
|||||||
|
|
||||||
@plugin.subscribe("shutdown")
|
@plugin.subscribe("shutdown")
|
||||||
def shutdown(plugin, **kwargs):
|
def shutdown(plugin, **kwargs):
|
||||||
plugin.log("received shutdown notification")
|
|
||||||
|
|
||||||
# 'shutdown' notification can be called in two ways, from `plugin stop` or from
|
# 'shutdown' notification can be called in two ways, from `plugin stop` or from
|
||||||
# lightningd's shutdown loop, we test which one by making `getinfo` call
|
# lightningd's shutdown loop, we test which one by making `getinfo` call
|
||||||
try:
|
try:
|
||||||
plugin.rpc.getinfo()
|
plugin.rpc.getinfo()
|
||||||
plugin.rpc.datastore(key='test', string='Allowed', mode="create-or-append")
|
plugin.rpc.datastore(key='test', string='Allowed', mode="create-or-append")
|
||||||
plugin.log("datastore success")
|
plugin.log("via plugin stop, datastore success")
|
||||||
except RpcError as e:
|
except RpcError as e:
|
||||||
if e.error == {'code': -5, 'message': 'lightningd is shutting down'}:
|
if e.error == {'code': -5, 'message': 'lightningd is shutting down'}:
|
||||||
# JSON RPC is disabled by now, but can do logging
|
# JSON RPC is disabled by now, but can do logging
|
||||||
with pytest.raises(RpcError, match=r'-5.*lightningd is shutting down'):
|
with pytest.raises(RpcError, match=r'-5.*lightningd is shutting down'):
|
||||||
plugin.rpc.datastore(key='test', string='Not allowed', mode="create-or-append")
|
plugin.rpc.datastore(key='test', string='Not allowed', mode="create-or-append")
|
||||||
plugin.log("datastore failed")
|
plugin.log("via lightningd shutdown, datastore failed")
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
plugin.log("delaying shutdown with 5s")
|
|
||||||
sleep(5)
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1084,38 +1084,6 @@ def test_htlc_accepted_hook_direct_restart(node_factory, executor):
|
|||||||
f1.result()
|
f1.result()
|
||||||
|
|
||||||
|
|
||||||
def test_htlc_accepted_hook_shutdown(node_factory, executor):
|
|
||||||
"""Hooks of important-plugins are never removed and these plugins are kept
|
|
||||||
alive until after subdaemons are shutdown. Also tests shutdown notification.
|
|
||||||
"""
|
|
||||||
l1, l2 = node_factory.line_graph(2, opts=[
|
|
||||||
{'may_reconnect': True, 'log-level': 'info'},
|
|
||||||
{'may_reconnect': True, 'log-level': 'debug',
|
|
||||||
'plugin': [os.path.join(os.getcwd(), 'tests/plugins/misc_notifications.py')],
|
|
||||||
'important-plugin': [os.path.join(os.getcwd(), 'tests/plugins/fail_htlcs.py')]}
|
|
||||||
])
|
|
||||||
|
|
||||||
l2.rpc.plugin_stop(os.path.join(os.getcwd(), 'tests/plugins/misc_notifications.py'))
|
|
||||||
l2.daemon.wait_for_log(r'datastore success')
|
|
||||||
l2.rpc.plugin_start(os.path.join(os.getcwd(), 'tests/plugins/misc_notifications.py'))
|
|
||||||
|
|
||||||
i1 = l2.rpc.invoice(msatoshi=1000, label="inv1", description="desc")['bolt11']
|
|
||||||
|
|
||||||
# fail_htlcs.py makes payment fail
|
|
||||||
with pytest.raises(RpcError):
|
|
||||||
l1.rpc.pay(i1)
|
|
||||||
|
|
||||||
f_stop = executor.submit(l2.rpc.stop)
|
|
||||||
l2.daemon.wait_for_log(r'plugin-misc_notifications.py: delaying shutdown with 5s')
|
|
||||||
|
|
||||||
# Should still fail htlc while shutting down
|
|
||||||
with pytest.raises(RpcError):
|
|
||||||
l1.rpc.pay(i1)
|
|
||||||
|
|
||||||
l2.daemon.wait_for_log(r'datastore failed')
|
|
||||||
f_stop.result()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.developer("without DEVELOPER=1, gossip v slow")
|
@pytest.mark.developer("without DEVELOPER=1, gossip v slow")
|
||||||
def test_htlc_accepted_hook_forward_restart(node_factory, executor):
|
def test_htlc_accepted_hook_forward_restart(node_factory, executor):
|
||||||
"""l2 restarts while it is pondering what to do with an HTLC.
|
"""l2 restarts while it is pondering what to do with an HTLC.
|
||||||
@@ -2593,22 +2561,33 @@ plugin.run()
|
|||||||
|
|
||||||
|
|
||||||
def test_plugin_shutdown(node_factory):
|
def test_plugin_shutdown(node_factory):
|
||||||
"""test 'shutdown' notification"""
|
"""test 'shutdown' notifications, via `plugin stop` or via `stop`"""
|
||||||
|
|
||||||
p = os.path.join(os.getcwd(), "tests/plugins/test_libplugin")
|
p = os.path.join(os.getcwd(), "tests/plugins/test_libplugin")
|
||||||
l1 = node_factory.get_node(options={'plugin': p})
|
p2 = os.path.join(os.getcwd(), 'tests/plugins/misc_notifications.py')
|
||||||
|
l1 = node_factory.get_node(options={'plugin': [p, p2]})
|
||||||
|
|
||||||
l1.rpc.plugin_stop(p)
|
l1.rpc.plugin_stop(p)
|
||||||
l1.daemon.wait_for_log(r"test_libplugin: shutdown called")
|
l1.daemon.wait_for_log(r"test_libplugin: shutdown called")
|
||||||
# FIXME: clean this up!
|
# FIXME: clean this up!
|
||||||
l1.daemon.wait_for_log(r"test_libplugin: Killing plugin: exited during normal operation")
|
l1.daemon.wait_for_log(r"test_libplugin: Killing plugin: exited during normal operation")
|
||||||
|
|
||||||
# Now try timeout.
|
# Via `plugin stop` it can make RPC calls before it (self-)terminates
|
||||||
|
l1.rpc.plugin_stop(p2)
|
||||||
|
l1.daemon.wait_for_log(r'misc_notifications.py: via plugin stop, datastore success')
|
||||||
|
l1.rpc.plugin_start(p2)
|
||||||
|
|
||||||
|
# Now try timeout via `plugin stop`
|
||||||
l1.rpc.plugin_start(p, dont_shutdown=True)
|
l1.rpc.plugin_start(p, dont_shutdown=True)
|
||||||
l1.rpc.plugin_stop(p)
|
l1.rpc.plugin_stop(p)
|
||||||
l1.daemon.wait_for_log(r"test_libplugin: shutdown called")
|
l1.daemon.wait_for_log(r"test_libplugin: shutdown called")
|
||||||
l1.daemon.wait_for_log(r"test_libplugin: Timeout on shutdown: killing anyway")
|
l1.daemon.wait_for_log(r"test_libplugin: Timeout on shutdown: killing anyway")
|
||||||
|
|
||||||
# Now, should also shutdown on finish.
|
# Now, should also shutdown or timeout on finish, RPC calls then fail with error code -5
|
||||||
l1.rpc.plugin_start(p)
|
l1.rpc.plugin_start(p, dont_shutdown=True)
|
||||||
|
needle = l1.daemon.logsearch_start
|
||||||
l1.rpc.stop()
|
l1.rpc.stop()
|
||||||
l1.daemon.wait_for_log(r"test_libplugin: shutdown called")
|
l1.daemon.wait_for_log(r"test_libplugin: shutdown called")
|
||||||
|
l1.daemon.logsearch_start = needle # we don't know what comes first
|
||||||
|
l1.daemon.is_in_log(r'misc_notifications.py: via lightningd shutdown, datastore failed')
|
||||||
|
l1.daemon.is_in_log(r'test_libplugin: failed to self-terminate in time, killing.')
|
||||||
|
|||||||
Reference in New Issue
Block a user