Skip to content

Commit

Permalink
pytest: test that we maintain load order unless hook deps require a c…
Browse files Browse the repository at this point in the history
…hange.

Suggested-by: @mschmook
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Nov 2, 2020
1 parent 83713d3 commit ece24e5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/plugins/dep_d.py
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions tests/plugins/dep_e.py
Original file line number Diff line number Diff line change
@@ -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 changes: 25 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2031,3 +2031,28 @@ def test_hook_dep(node_factory):
# Complaints about unknown plugin a, but nothing else
assert 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")

0 comments on commit ece24e5

Please sign in to comment.