move on_read.first to earlier

This commit is contained in:
Lex Berezhny 2020-03-30 17:02:08 -04:00
parent ed38966edb
commit a8153627c6
2 changed files with 5 additions and 15 deletions

View file

@ -316,12 +316,12 @@ class Ledger(metaclass=LedgerRegistry):
self.db.open(),
self.headers.open()
])
first_connection = self.network.on_connected.first
first_ready = self.on_ready.first
asyncio.ensure_future(self.network.start())
await first_connection
fully_synced = self.on_ready.first
asyncio.create_task(self.network.start())
await self.network.on_connected.first
async with self._header_processing_lock:
await self._update_tasks.add(self.initial_headers_sync())
await fully_synced
await asyncio.gather(*(a.maybe_migrate_certificates() for a in self.accounts))
await asyncio.gather(*(a.save_max_gap() for a in self.accounts))
if len(self.accounts) > 10:
@ -329,12 +329,9 @@ class Ledger(metaclass=LedgerRegistry):
else:
await self._report_state()
self.on_transaction.listen(self._reset_balance_cache)
await first_ready
async def join_network(self, *_):
log.info("Subscribing and updating accounts.")
async with self._header_processing_lock:
await self._update_tasks.add(self.initial_headers_sync())
await self._update_tasks.add(self.subscribe_accounts())
await self._update_tasks.done.wait()
self._on_ready_controller.add(True)

View file

@ -60,14 +60,7 @@ class NetworkTests(IntegrationTestCase):
}, await self.ledger.network.get_server_features())
class NetworkConnectionTests(IntegrationTestCase):
async def test_on_ready_listening_before_event_fix_2896(self):
await self.ledger.stop()
# slow down other parts to make network finish first and fire on_ready
self.account.maybe_migrate_certificates = lambda: asyncio.sleep(2)
await asyncio.wait_for(self.ledger.start(), timeout=3)
# above ledger.start() will fail if on_ready fired before listening
class ReconnectTests(IntegrationTestCase):
async def test_multiple_servers(self):
# we have a secondary node that connects later, so