fix fastest session for when online but unavailable

This commit is contained in:
Victor Shyba 2019-09-24 03:23:09 -03:00 committed by Lex Berezhny
parent aa90257ec7
commit b3f087dbc7
2 changed files with 11 additions and 1 deletions

View file

@ -115,6 +115,13 @@ class ReconnectTests(IntegrationTestCase):
await self.ledger.network.on_connected.first await self.ledger.network.on_connected.first
self.assertTrue(self.ledger.network.is_connected) self.assertTrue(self.ledger.network.is_connected)
async def test_online_but_still_unavailable(self):
# Edge case. See issue #2445 for context
self.assertIsNotNone(self.ledger.network.session_pool.fastest_session)
for session in self.ledger.network.session_pool.sessions:
session.response_time = None
self.assertIsNone(self.ledger.network.session_pool.fastest_session)
class ServerPickingTestCase(AsyncioTestCase): class ServerPickingTestCase(AsyncioTestCase):

View file

@ -185,6 +185,9 @@ class BaseNetwork:
async def start(self): async def start(self):
self.running = True self.running = True
self._switch_task = asyncio.ensure_future(self.switch_forever()) self._switch_task = asyncio.ensure_future(self.switch_forever())
# this may become unnecessary when there are no more bugs found,
# but for now it helps understanding log reports
self._switch_task.add_done_callback(lambda _: log.info("Wallet client switching task stopped."))
self.session_pool.start(self.config['default_servers']) self.session_pool.start(self.config['default_servers'])
self.on_header.listen(self._update_remote_height) self.on_header.listen(self._update_remote_height)
@ -284,7 +287,7 @@ class SessionPool:
return None return None
return min( return min(
[((session.response_time + session.connection_latency) * (session.pending_amount + 1), session) [((session.response_time + session.connection_latency) * (session.pending_amount + 1), session)
for session in self.available_sessions], for session in self.available_sessions] or [(0, None)],
key=itemgetter(0) key=itemgetter(0)
)[1] )[1]