ttests: made TestLNTransport.test_loop more robust - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit dae842e2ad411bdd0bf3c45cc10a21f5407c93a1 DIR parent 7962e17df67f0196af7ebdf2780d04a80a8ccedc HTML Author: SomberNight <somber.night@protonmail.com> Date: Wed, 4 Mar 2020 17:57:40 +0100 ttests: made TestLNTransport.test_loop more robust Diffstat: M electrum/lnworker.py | 3 ++- M electrum/tests/test_lntransport.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) --- DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py t@@ -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}") DIR diff --git a/electrum/tests/test_lntransport.py b/electrum/tests/test_lntransport.py t@@ -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) t@@ -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())