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 = []
@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()

11
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)

Loading…
Cancel
Save