From 67f2939540a0cdb7516577e894511676f12a6fce Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Wed, 27 Jan 2021 12:56:29 +0100 Subject: [PATCH] pytest: custommsg chainable tests --- .../plugins/{custommsg.py => custommsg_a.py} | 2 +- tests/plugins/custommsg_b.py | 16 +++++++++++++ tests/test_misc.py | 24 ++++++++++++------- 3 files changed, 33 insertions(+), 9 deletions(-) rename tests/plugins/{custommsg.py => custommsg_a.py} (78%) create mode 100755 tests/plugins/custommsg_b.py diff --git a/tests/plugins/custommsg.py b/tests/plugins/custommsg_a.py similarity index 78% rename from tests/plugins/custommsg.py rename to tests/plugins/custommsg_a.py index 652588167..fcc7ac133 100755 --- a/tests/plugins/custommsg.py +++ b/tests/plugins/custommsg_a.py @@ -6,7 +6,7 @@ plugin = Plugin() @plugin.hook('custommsg') def on_custommsg(peer_id, message, plugin, **kwargs): - plugin.log("Got a custom message {msg} from peer {peer_id}".format( + plugin.log("Got custommessage_a {msg} from peer {peer_id}".format( msg=message, peer_id=peer_id )) diff --git a/tests/plugins/custommsg_b.py b/tests/plugins/custommsg_b.py new file mode 100755 index 000000000..3f9ab307b --- /dev/null +++ b/tests/plugins/custommsg_b.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +from pyln.client import Plugin + +plugin = Plugin() + + +@plugin.hook('custommsg') +def on_custommsg(peer_id, message, plugin, **kwargs): + plugin.log("Got custommessage_b {msg} from peer {peer_id}".format( + msg=message, + peer_id=peer_id + )) + return {'result': 'continue'} + + +plugin.run() diff --git a/tests/test_misc.py b/tests/test_misc.py index f39c0570f..57dc78b87 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -2239,8 +2239,10 @@ def test_sendcustommsg(node_factory): and we can't send to it. """ - plugin = os.path.join(os.path.dirname(__file__), "plugins", "custommsg.py") - opts = {'log-level': 'io', 'plugin': plugin} + opts = {'log-level': 'io', 'plugin': [ + os.path.join(os.path.dirname(__file__), "plugins", "custommsg_b.py"), + os.path.join(os.path.dirname(__file__), "plugins", "custommsg_a.py") + ]} l1, l2, l3, l4 = node_factory.get_nodes(4, opts=opts) node_factory.join_nodes([l1, l2, l3]) l2.connect(l4) @@ -2279,9 +2281,12 @@ def test_sendcustommsg(node_factory): ) ) l1.daemon.wait_for_log(r'\[IN\] {}'.format(serialized)) - l1.daemon.wait_for_log( - r'Got a custom message {serialized} from peer {peer_id}'.format( - serialized=serialized, peer_id=l2.info['id'])) + l1.daemon.wait_for_logs([ + r'Got custommessage_a {serialized} from peer {peer_id}'.format( + serialized=serialized, peer_id=l2.info['id']), + r'Got custommessage_b {serialized} from peer {peer_id}'.format( + serialized=serialized, peer_id=l2.info['id']) + ]) # This should work since the peer is currently owned by `openingd` l2.rpc.dev_sendcustommsg(l4.info['id'], msg) @@ -2291,9 +2296,12 @@ def test_sendcustommsg(node_factory): ) ) l4.daemon.wait_for_log(r'\[IN\] {}'.format(serialized)) - l4.daemon.wait_for_log( - r'Got a custom message {serialized} from peer {peer_id}'.format( - serialized=serialized, peer_id=l2.info['id'])) + l4.daemon.wait_for_logs([ + r'Got custommessage_a {serialized} from peer {peer_id}'.format( + serialized=serialized, peer_id=l2.info['id']), + r'Got custommessage_b {serialized} from peer {peer_id}'.format( + serialized=serialized, peer_id=l2.info['id']), + ]) def test_sendonionmessage(node_factory):