]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: make AEvent.wait_timeout() return False on timeout
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 15 Sep 2025 23:41:35 +0000 (01:41 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 13 Oct 2025 11:26:01 +0000 (13:26 +0200)
For better similarity to Event.wait().

tests/acompat.py
tests/pool/test_pool.py
tests/pool/test_pool_async.py
tests/pool/test_pool_common.py
tests/pool/test_pool_common_async.py
tests/pool/test_pool_null.py
tests/pool/test_pool_null_async.py

index 868b682ec0e19d7e34ee748f46d7a40388840876..f2a13367b10d4e235a2c57e3c16e608270ab1d2e 100644 (file)
@@ -115,7 +115,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]  # can be dropped after Python 3.8
index f31aea60450a69ab61c98f6ab5a98dcc7c48034d..a0e6b2aec4af7f9b51d09968f7450669f5c8cc47 100644 (file)
@@ -578,14 +578,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()
 
@@ -615,7 +615,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
@@ -965,7 +965,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
index 7bfb0139aa899a6e66b39d1a1a16c40faace7cb2..a301b07e05d7d26ea14295d82891a3e751c9d242 100644 (file)
@@ -581,14 +581,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()
 
@@ -618,7 +618,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
@@ -968,7 +968,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
index 3c21c098009e5a3c2cd698588d23871768cad2a9..d70e7ade36b1350929400959d1205d6e31f6147a 100644 (file)
@@ -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
index 068064d684e9bb5bd012bffc65dd5834bd768df4..beaa7f65fbf3b44fadf3b5062f6aba22b327ef8b 100644 (file)
@@ -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
index fb2157980e326f11ed373e1a011054cbc9ee0a6c..de9d499ba645eb71b69fbb894b0efa1156907469 100644 (file)
@@ -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
index 87e2411d3a2b97b7841367efc0d045d7a7b239a8..6ba57a0957e41e5f5feb010c4c8254b2f566701a 100644 (file)
@@ -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