Browse Source

pytest: test that we maintain load order unless hook deps require a change.

Suggested-by: @mschmook
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-prep
Rusty Russell 4 years ago
committed by neil saitug
parent
commit
d429e21db3
  1. 15
      tests/plugins/dep_d.py
  2. 15
      tests/plugins/dep_e.py
  3. 25
      tests/test_plugin.py

15
tests/plugins/dep_d.py

@ -0,0 +1,15 @@
#!/usr/bin/env python3
from pyln.client import Plugin
"""A simple plugin that must come before dep_e.
"""
plugin = Plugin()
@plugin.hook('htlc_accepted', before=['dep_e.py'])
def on_htlc_accepted(htlc, plugin, **kwargs):
print("htlc_accepted called")
return {'result': 'continue'}
plugin.run()

15
tests/plugins/dep_e.py

@ -0,0 +1,15 @@
#!/usr/bin/env python3
from pyln.client import Plugin
"""A simple plugin that registers an htlc_accepted hook..
"""
plugin = Plugin()
@plugin.hook('htlc_accepted')
def on_htlc_accepted(htlc, plugin, **kwargs):
print("htlc_accepted called")
return {'result': 'continue'}
plugin.run()

25
tests/test_plugin.py

@ -2116,3 +2116,28 @@ def test_hook_dep(node_factory):
# Complaints about unknown plugin a, but nothing else # Complaints about unknown plugin a, but nothing else
assert l1.daemon.is_in_log("unknown plugin dep_a.py") assert l1.daemon.is_in_log("unknown plugin dep_a.py")
assert not l1.daemon.is_in_log("unknown plugin (?!dep_a.py)") assert not l1.daemon.is_in_log("unknown plugin (?!dep_a.py)")
@pytest.mark.xfail(strict=True)
def test_hook_dep_stable(node_factory):
# Load in order A, D, E, B.
# A says it has to be before B, D says it has to be before E.
# It should load in the order specified.
dep_a = os.path.join(os.path.dirname(__file__), 'plugins/dep_a.py')
dep_b = os.path.join(os.path.dirname(__file__), 'plugins/dep_b.py')
dep_d = os.path.join(os.path.dirname(__file__), 'plugins/dep_d.py')
dep_e = os.path.join(os.path.dirname(__file__), 'plugins/dep_e.py')
l1, l2 = node_factory.line_graph(2, opts=[{},
{'plugin': [dep_a, dep_d, dep_e, dep_b]}])
# dep_a mentions deb_c, but nothing else should be unknown.
assert l2.daemon.is_in_log("unknown plugin dep_c.py")
assert not l2.daemon.is_in_log("unknown plugin (?!|dep_c.py)")
l1.pay(l2, 100000)
# They must be called in this order!
l2.daemon.wait_for_log(r"dep_a.py: htlc_accepted called")
l2.daemon.wait_for_log(r"dep_d.py: htlc_accepted called")
l2.daemon.wait_for_log(r"dep_e.py: htlc_accepted called")
l2.daemon.wait_for_log(r"dep_b.py: htlc_accepted called")

Loading…
Cancel
Save