commit dae842e2ad411bdd0bf3c45cc10a21f5407c93a1
parent 7962e17df67f0196af7ebdf2780d04a80a8ccedc
Author: SomberNight <somber.night@protonmail.com>
Date: Wed, 4 Mar 2020 17:57:40 +0100
tests: made TestLNTransport.test_loop more robust
Diffstat:
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
@@ -169,7 +169,8 @@ class LNWorker(Logger):
self.peers[node_id] = peer
await self.taskgroup.spawn(peer.main_loop())
try:
- await asyncio.start_server(cb, addr, int(port))
+ # FIXME: server.close(), server.wait_closed(), etc... ?
+ server = await asyncio.start_server(cb, addr, int(port))
except OSError as e:
self.logger.error(f"cannot listen for lightning p2p. error: {e!r}")
diff --git a/electrum/tests/test_lntransport.py b/electrum/tests/test_lntransport.py
@@ -51,6 +51,7 @@ class TestLNTransport(ElectrumTestCase):
responder_shaked.set()
server_future = asyncio.ensure_future(asyncio.start_server(cb, '127.0.0.1', 42898))
loop.run_until_complete(server_future)
+ server = server_future.result() # type: asyncio.Server
async def connect():
peer_addr = LNPeerAddr('127.0.0.1', 42898, responder_key.get_public_key_bytes())
t = LNTransport(initiator_key.get_secret_bytes(), peer_addr)
@@ -59,6 +60,10 @@ class TestLNTransport(ElectrumTestCase):
self.assertEqual(await t.read_messages().__anext__(), b'hello from server')
server_shaked.set()
- connect_future = asyncio.ensure_future(connect())
- loop.run_until_complete(responder_shaked.wait())
- loop.run_until_complete(server_shaked.wait())
+ try:
+ connect_future = asyncio.ensure_future(connect())
+ loop.run_until_complete(responder_shaked.wait())
+ loop.run_until_complete(server_shaked.wait())
+ finally:
+ server.close()
+ loop.run_until_complete(server.wait_closed())