forked from LBRYCommunity/lbry-sdk
wait for lbrycrd on start
This commit is contained in:
parent
47a8c005d9
commit
a5c117b542
3 changed files with 21 additions and 1 deletions
|
@ -243,6 +243,8 @@ class Lbrycrd:
|
|||
self.subscription = None
|
||||
|
||||
async def rpc(self, method, params=None):
|
||||
if self.session.closed:
|
||||
raise Exception("session is closed! We are shutting down.")
|
||||
message = {
|
||||
"jsonrpc": "1.0",
|
||||
"id": "1",
|
||||
|
|
|
@ -43,9 +43,19 @@ class BlockchainSync(Sync):
|
|||
self.advance_loop_task: Optional[asyncio.Task] = None
|
||||
self.advance_loop_event = asyncio.Event()
|
||||
|
||||
async def wait_for_chain_ready(self):
|
||||
while True:
|
||||
try:
|
||||
return await self.chain.ensure_subscribable()
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.warning("Blockchain not ready, waiting for it: %s", str(e))
|
||||
await asyncio.sleep(1)
|
||||
|
||||
async def start(self):
|
||||
self.db.stop_event.clear()
|
||||
await self.chain.ensure_subscribable()
|
||||
await self.wait_for_chain_ready()
|
||||
self.advance_loop_task = asyncio.create_task(self.advance())
|
||||
await self.advance_loop_task
|
||||
await self.chain.subscribe()
|
||||
|
|
|
@ -613,6 +613,14 @@ class TestMultiBlockFileSyncing(BasicBlockchainTestCase):
|
|||
|
||||
|
||||
class TestGeneralBlockchainSync(SyncingBlockchainTestCase):
|
||||
async def test_sync_waits_for_lbrycrd_to_start(self):
|
||||
await self.sync.stop()
|
||||
await self.chain.stop()
|
||||
sync_start = asyncio.ensure_future(self.sync.start())
|
||||
await asyncio.sleep(0)
|
||||
await self.chain.start()
|
||||
await sync_start
|
||||
self.assertTrue(sync_start.done()) # test goal is to get here without exceptions
|
||||
|
||||
async def test_sync_advances(self):
|
||||
blocks = []
|
||||
|
|
Loading…
Reference in a new issue