From f35c2c7fab09bebeeb64440c5aa663c6b1f0e017 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 16 Sep 2025 01:41:35 +0200 Subject: [PATCH] test: make AEvent.wait_timeout() return False on timeout For better similarity to Event.wait(). --- tests/acompat.py | 5 ++++- tests/pool/test_pool.py | 8 ++++---- tests/pool/test_pool_async.py | 8 ++++---- tests/pool/test_pool_common.py | 2 +- tests/pool/test_pool_common_async.py | 2 +- tests/pool/test_pool_null.py | 2 +- tests/pool/test_pool_null_async.py | 2 +- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/acompat.py b/tests/acompat.py index b65d16d55..b4de82151 100644 --- a/tests/acompat.py +++ b/tests/acompat.py @@ -96,7 +96,10 @@ class AEvent(asyncio.Event): """ async def wait_timeout(self, timeout): - await asyncio.wait_for(self.wait(), timeout) + try: + return await asyncio.wait_for(self.wait(), timeout) + except asyncio.TimeoutError: + return False class Queue(queue.Queue): # type: ignore[type-arg] diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index c5a9ae346..68064a014 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -579,14 +579,14 @@ def test_reconnect_after_grow_failed(proxy): with pool.ConnectionPool( proxy.client_dsn, min_size=4, reconnect_timeout=1.0, reconnect_failed=failed ) as p: - ev.wait(2.0) + assert ev.wait(2.0) with pytest.raises(pool.PoolTimeout): with p.connection(timeout=0.5) as conn: pass ev.clear() - ev.wait(2.0) + assert ev.wait(2.0) proxy.start() @@ -616,7 +616,7 @@ def test_refill_on_check(proxy): # Checking the pool will empty it p.check() - ev.wait(2.0) + assert ev.wait(2.0) assert len(p._pool) == 0 # Allow to connect again @@ -966,7 +966,7 @@ def test_cancellation_in_queue(dsn): tasks = [spawn(worker, (i,)) for i in range(nconns * 3)] # wait until the pool has served all the connections and clients are queued. - ev.wait(3.0) + assert ev.wait(3.0) for i in range(10): if p.get_stats().get("requests_queued", 0): break diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index e288a27e9..d4a2d277a 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -582,14 +582,14 @@ async def test_reconnect_after_grow_failed(proxy): async with pool.AsyncConnectionPool( proxy.client_dsn, min_size=4, reconnect_timeout=1.0, reconnect_failed=failed ) as p: - await ev.wait_timeout(2.0) + assert await ev.wait_timeout(2.0) with pytest.raises(pool.PoolTimeout): async with p.connection(timeout=0.5) as conn: pass ev.clear() - await ev.wait_timeout(2.0) + assert await ev.wait_timeout(2.0) proxy.start() @@ -619,7 +619,7 @@ async def test_refill_on_check(proxy): # Checking the pool will empty it await p.check() - await ev.wait_timeout(2.0) + assert await ev.wait_timeout(2.0) assert len(p._pool) == 0 # Allow to connect again @@ -969,7 +969,7 @@ async def test_cancellation_in_queue(dsn): tasks = [spawn(worker, (i,)) for i in range(nconns * 3)] # wait until the pool has served all the connections and clients are queued. - await ev.wait_timeout(3.0) + assert await ev.wait_timeout(3.0) for i in range(10): if p.get_stats().get("requests_queued", 0): break diff --git a/tests/pool/test_pool_common.py b/tests/pool/test_pool_common.py index 3c21c0980..d70e7ade3 100644 --- a/tests/pool/test_pool_common.py +++ b/tests/pool/test_pool_common.py @@ -673,7 +673,7 @@ def test_cancellation_in_queue(pool_cls, dsn): tasks = [spawn(worker, (i,)) for i in range(nconns * 3)] # wait until the pool has served all the connections and clients are queued. - ev.wait(3.0) + assert ev.wait(3.0) for i in range(10): if p.get_stats().get("requests_queued", 0): break diff --git a/tests/pool/test_pool_common_async.py b/tests/pool/test_pool_common_async.py index 068064d68..beaa7f65f 100644 --- a/tests/pool/test_pool_common_async.py +++ b/tests/pool/test_pool_common_async.py @@ -684,7 +684,7 @@ async def test_cancellation_in_queue(pool_cls, dsn): tasks = [spawn(worker, (i,)) for i in range(nconns * 3)] # wait until the pool has served all the connections and clients are queued. - await ev.wait_timeout(3.0) + assert await ev.wait_timeout(3.0) for i in range(10): if p.get_stats().get("requests_queued", 0): break diff --git a/tests/pool/test_pool_null.py b/tests/pool/test_pool_null.py index 9d84e4ae7..c462a19d5 100644 --- a/tests/pool/test_pool_null.py +++ b/tests/pool/test_pool_null.py @@ -477,7 +477,7 @@ def test_cancellation_in_queue(dsn): tasks = [spawn(worker, (i,)) for i in range(nconns * 3)] # wait until the pool has served all the connections and clients are queued. - ev.wait(3.0) + assert ev.wait(3.0) for i in range(10): if p.get_stats().get("requests_queued", 0): break diff --git a/tests/pool/test_pool_null_async.py b/tests/pool/test_pool_null_async.py index 1d40c6dd5..a66982b23 100644 --- a/tests/pool/test_pool_null_async.py +++ b/tests/pool/test_pool_null_async.py @@ -479,7 +479,7 @@ async def test_cancellation_in_queue(dsn): tasks = [spawn(worker, (i,)) for i in range(nconns * 3)] # wait until the pool has served all the connections and clients are queued. - await ev.wait_timeout(3.0) + assert await ev.wait_timeout(3.0) for i in range(10): if p.get_stats().get("requests_queued", 0): break -- 2.47.3