From 51be734a0850c5a60b8048059d36078061af6607 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 18 Feb 2022 18:47:01 -0300 Subject: [PATCH] add a way to wait announcements to finish so tests are reliable --- lbry/dht/blob_announcer.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lbry/dht/blob_announcer.py b/lbry/dht/blob_announcer.py index 24cf18bbe..e4da3cfa9 100644 --- a/lbry/dht/blob_announcer.py +++ b/lbry/dht/blob_announcer.py @@ -27,6 +27,7 @@ class BlobAnnouncer: self.storage = storage self.announce_task: asyncio.Task = None self.announce_queue: typing.List[str] = [] + self._done = asyncio.Event() async def _submit_announcement(self, blob_hash): try: @@ -64,6 +65,8 @@ class BlobAnnouncer: if announced: await self.storage.update_last_announced_blobs(announced) log.info("announced %i blobs", len(announced)) + self._done.set() + self._done.clear() def start(self, batch_size: typing.Optional[int] = 10): assert not self.announce_task or self.announce_task.done(), "already running" @@ -72,3 +75,6 @@ class BlobAnnouncer: def stop(self): if self.announce_task and not self.announce_task.done(): self.announce_task.cancel() + + def wait(self): + return self._done.wait()