From ece24e5c98718914b91bfb77a261d17086f891fb Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 2 Nov 2020 13:08:01 +1030 Subject: [PATCH] pytest: test that we maintain load order unless hook deps require a change. Suggested-by: @mschmook Signed-off-by: Rusty Russell --- tests/plugins/dep_d.py | 15 +++++++++++++++ tests/plugins/dep_e.py | 15 +++++++++++++++ tests/test_plugin.py | 25 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100755 tests/plugins/dep_d.py create mode 100755 tests/plugins/dep_e.py diff --git a/tests/plugins/dep_d.py b/tests/plugins/dep_d.py new file mode 100755 index 000000000000..2f5fb935fda3 --- /dev/null +++ b/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() diff --git a/tests/plugins/dep_e.py b/tests/plugins/dep_e.py new file mode 100755 index 000000000000..6d1b679df04f --- /dev/null +++ b/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() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index caa50a94384d..d2628cd25974 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -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")