both exceptions can be raised, depending on when the call happens

This commit is contained in:
Victor Shyba 2019-08-06 02:54:11 -03:00
parent 8fce374cae
commit 022d60ec2c
4 changed files with 5 additions and 5 deletions

View file

@ -26,7 +26,7 @@ class TestSessionBloat(IntegrationTestCase):
self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 1) self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 1)
self.assertFalse(session.is_closing()) self.assertFalse(session.is_closing())
await asyncio.sleep(1.1) await asyncio.sleep(1.1)
with self.assertRaises(asyncio.TimeoutError): with self.assertRaises((asyncio.TimeoutError, asyncio.CancelledError)):
await session.send_request('server.banner', ()) await session.send_request('server.banner', ())
self.assertTrue(session.is_closing()) self.assertTrue(session.is_closing())
self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 0) self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 0)

View file

@ -35,7 +35,7 @@ class ReconnectTests(IntegrationTestCase):
d = self.ledger.network.get_transaction(sendtxid) d = self.ledger.network.get_transaction(sendtxid)
# what's that smoke on my ethernet cable? oh no! # what's that smoke on my ethernet cable? oh no!
self.ledger.network.client.connection_lost(Exception()) self.ledger.network.client.connection_lost(Exception())
with self.assertRaises(asyncio.CancelledError): with self.assertRaises((asyncio.TimeoutError, asyncio.CancelledError)):
await d await d
# rich but offline? no way, no water, let's retry # rich but offline? no way, no water, let's retry
with self.assertRaisesRegex(ConnectionError, 'connection is not available'): with self.assertRaisesRegex(ConnectionError, 'connection is not available'):

View file

@ -169,10 +169,10 @@ class BaseNetwork:
return self.rpc('blockchain.block.headers', [height, count]) return self.rpc('blockchain.block.headers', [height, count])
def subscribe_headers(self): def subscribe_headers(self):
return self.client.send_request('blockchain.headers.subscribe', [True]) return self.rpc('blockchain.headers.subscribe', [True])
def subscribe_address(self, address): def subscribe_address(self, address):
return self.client.send_request('blockchain.address.subscribe', [address]) return self.rpc('blockchain.address.subscribe', [address])
class SessionPool: class SessionPool:

View file

@ -474,7 +474,7 @@ class RPCSession(SessionBase):
async def send_request(self, method, args=()): async def send_request(self, method, args=()):
"""Send an RPC request over the network.""" """Send an RPC request over the network."""
if self.is_closing(): if self.is_closing():
raise CancelledError() raise asyncio.TimeoutError()
message, event = self.connection.send_request(Request(method, args)) message, event = self.connection.send_request(Request(method, args))
await self._send_message(message) await self._send_message(message)
await event.wait() await event.wait()