From daef4c2be51db1103b0b745470271846f251e1e6 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 23 Jan 2019 18:45:54 +0100 Subject: [PATCH] fixup! pylightning: Add a small test for async rpcmethods --- tests/plugins/asynctest.py | 13 +++++++------ tests/test_plugin.py | 11 +++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/plugins/asynctest.py b/tests/plugins/asynctest.py index 6786d904d..758b96d5c 100755 --- a/tests/plugins/asynctest.py +++ b/tests/plugins/asynctest.py @@ -12,16 +12,17 @@ plugin = Plugin() requests = [] -@plugin.method('callme', sync=False) -def callme(i, request): +@plugin.method('asyncqueue', sync=False) +def async_queue(request): global requests - requests.append(request) - if len(requests) < 5: - return + +@plugin.method('asyncflush') +def async_flush(res): + global requests for r in requests: - r.set_result(i) + r.set_result(res) plugin.run() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 3a071cd35..c552b1772 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -4,6 +4,7 @@ from lightning import RpcError import pytest import subprocess +import time def test_option_passthrough(node_factory): @@ -130,14 +131,16 @@ def test_async_rpcmethod(node_factory, executor): l1 = node_factory.get_node(options={'plugin': 'tests/plugins/asynctest.py'}) results = [] - for i in range(4): - results.append(executor.submit(l1.rpc.callme, i)) + for i in range(10): + results.append(executor.submit(l1.rpc.asyncqueue)) + + time.sleep(3) # None of these should have returned yet assert len([r for r in results if r.done()]) == 0 # This last one triggers the release and all results should be 42, # since the last number is returned for all - l1.rpc.callme(42) + l1.rpc.asyncflush(42) - assert [r.result() for r in results] == [42] * 4 + assert [r.result() for r in results] == [42] * len(results)