Browse Source

fixup! pylightning: Add a small test for async rpcmethods

pylightning-async
Christian Decker 6 years ago
parent
commit
daef4c2be5
No known key found for this signature in database GPG Key ID: 1416D83DC4F0E86D
  1. 13
      tests/plugins/asynctest.py
  2. 11
      tests/test_plugin.py

13
tests/plugins/asynctest.py

@ -12,16 +12,17 @@ plugin = Plugin()
requests = [] requests = []
@plugin.method('callme', sync=False) @plugin.method('asyncqueue', sync=False)
def callme(i, request): def async_queue(request):
global requests global requests
requests.append(request) requests.append(request)
if len(requests) < 5:
return
@plugin.method('asyncflush')
def async_flush(res):
global requests
for r in requests: for r in requests:
r.set_result(i) r.set_result(res)
plugin.run() plugin.run()

11
tests/test_plugin.py

@ -4,6 +4,7 @@ from lightning import RpcError
import pytest import pytest
import subprocess import subprocess
import time
def test_option_passthrough(node_factory): 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'}) l1 = node_factory.get_node(options={'plugin': 'tests/plugins/asynctest.py'})
results = [] results = []
for i in range(4): for i in range(10):
results.append(executor.submit(l1.rpc.callme, i)) results.append(executor.submit(l1.rpc.asyncqueue))
time.sleep(3)
# None of these should have returned yet # None of these should have returned yet
assert len([r for r in results if r.done()]) == 0 assert len([r for r in results if r.done()]) == 0
# This last one triggers the release and all results should be 42, # This last one triggers the release and all results should be 42,
# since the last number is returned for all # 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)

Loading…
Cancel
Save