]> 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 01:25:16 +0000 (03:25 +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 b65d16d5535a584e036f8c2676374abf1ba92001..b4de82151eb00ba47f5b5e6035f7bce824d94aa9 100644 (file)
@@ -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]
index c5a9ae3469a371876a6a8d5ee420762d915c3186..68064a014ab60471c3c9152d7eec10ee42eebf3b 100644 (file)
@@ -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
index e288a27e96ec8efd0bc2be1173899900151b8dab..d4a2d277af771c56036c23e903596d1bca57bbfd 100644 (file)
@@ -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
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 9d84e4ae725deb73671f60c6901466b05692df72..c462a19d5822cf671dc582763be24776e31dd75c 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 1d40c6dd55a41670a4b5d5395d6246651d4b3835..a66982b2329c7b50ca50cc2acb9a49a706e3f947 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