From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 7304E13835B for ; Mon, 18 Jan 2021 12:20:21 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BED72E087E; Mon, 18 Jan 2021 12:20:20 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A65FFE087E for ; Mon, 18 Jan 2021 12:20:20 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 58618340FA5 for ; Mon, 18 Jan 2021 12:20:19 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id AC1A049F for ; Mon, 18 Jan 2021 12:20:17 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1610969517.be0b5d33ee8b355dcc9932b52bb1e025e6bd58d4.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/futures/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/tests/util/futures/test_retry.py X-VCS-Directories: lib/portage/tests/util/futures/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: be0b5d33ee8b355dcc9932b52bb1e025e6bd58d4 X-VCS-Branch: master Date: Mon, 18 Jan 2021 12:20:17 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: c308841f-f200-4de9-a62b-06a39f0ceb99 X-Archives-Hash: aec1dcedfc609290b3e834ed552b6013 commit: be0b5d33ee8b355dcc9932b52bb1e025e6bd58d4 Author: Zac Medico gentoo org> AuthorDate: Mon Jan 18 11:16:53 2021 +0000 Commit: Zac Medico gentoo org> CommitDate: Mon Jan 18 11:31:57 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=be0b5d33 RetryTestCase: Use async and await syntax Signed-off-by: Zac Medico gentoo.org> lib/portage/tests/util/futures/test_retry.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/portage/tests/util/futures/test_retry.py b/lib/portage/tests/util/futures/test_retry.py index 6648b1b2c..bce48a693 100644 --- a/lib/portage/tests/util/futures/test_retry.py +++ b/lib/portage/tests/util/futures/test_retry.py @@ -1,4 +1,4 @@ -# Copyright 2018-2020 Gentoo Authors +# Copyright 2018-2021 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 from concurrent.futures import Future, ThreadPoolExecutor @@ -32,18 +32,11 @@ class SucceedLater: def __init__(self, duration): self._succeed_time = time.monotonic() + duration - def __call__(self): - loop = global_event_loop() - result = loop.create_future() + async def __call__(self): remaining = self._succeed_time - time.monotonic() if remaining > 0: - loop.call_soon_threadsafe(lambda: None if result.done() else - result.set_exception(SucceedLaterException( - 'time until success: {} seconds'.format(remaining)))) - else: - loop.call_soon_threadsafe(lambda: None if result.done() else - result.set_result('success')) - return result + await asyncio.sleep(remaining) + return 'success' class SucceedNeverException(Exception): @@ -54,20 +47,17 @@ class SucceedNever: """ A callable object that never succeeds. """ - def __call__(self): - loop = global_event_loop() - result = loop.create_future() - loop.call_soon_threadsafe(lambda: None if result.done() else - result.set_exception(SucceedNeverException('expected failure'))) - return result + async def __call__(self): + raise SucceedNeverException('expected failure') class HangForever: """ A callable object that sleeps forever. """ - def __call__(self): - return asyncio.Future() + async def __call__(self): + while True: + await asyncio.sleep(9) class RetryTestCase(TestCase):