pytest: add test that htlc_accepted hook only gets called after init.

We fail this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-08-10 14:54:55 +09:30 committed by Christian Decker
parent 49496ab3ba
commit f0ab4d72da
2 changed files with 20 additions and 0 deletions

View File

@ -34,4 +34,9 @@ def on_htlc_accepted(htlc, onion, plugin, **kwargs):
return {'result': 'continue'} return {'result': 'continue'}
@plugin.init()
def init(options, configuration, plugin):
plugin.log("hold_htlcs.py initializing")
plugin.run() plugin.run()

View File

@ -466,6 +466,7 @@ def test_htlc_accepted_hook_resolve(node_factory):
assert len(inv) == 1 and inv[0]['status'] == 'unpaid' assert len(inv) == 1 and inv[0]['status'] == 'unpaid'
@pytest.mark.xfail(strict=True)
def test_htlc_accepted_hook_direct_restart(node_factory, executor): def test_htlc_accepted_hook_direct_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.
""" """
@ -479,12 +480,19 @@ def test_htlc_accepted_hook_direct_restart(node_factory, executor):
f1 = executor.submit(l1.rpc.pay, i1) f1 = executor.submit(l1.rpc.pay, i1)
l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds') l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')
needle = l2.daemon.logsearch_start
l2.restart() l2.restart()
# Now it should try again, *after* initializing.
# This may be before "Server started with public key" swallowed by restart()
l2.daemon.logsearch_start = needle + 1
l2.daemon.wait_for_log(r'hold_htlcs.py initializing')
l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')
f1.result() f1.result()
@unittest.skipIf(not DEVELOPER, "without DEVELOPER=1, gossip v slow") @unittest.skipIf(not DEVELOPER, "without DEVELOPER=1, gossip v slow")
@pytest.mark.xfail(strict=True)
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.
""" """
@ -500,8 +508,15 @@ def test_htlc_accepted_hook_forward_restart(node_factory, executor):
l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds') l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')
needle = l2.daemon.logsearch_start
l2.restart() l2.restart()
# Now it should try again, *after* initializing.
# This may be before "Server started with public key" swallowed by restart()
l2.daemon.logsearch_start = needle + 1
l2.daemon.wait_for_log(r'hold_htlcs.py initializing')
l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')
# Grab the file where the plugin wrote the onion and read it in for some # Grab the file where the plugin wrote the onion and read it in for some
# additional checks # additional checks
logline = l2.daemon.wait_for_log(r'Onion written to') logline = l2.daemon.wait_for_log(r'Onion written to')