]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test(pool): skip cancellation tests on Python 3.7
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 19 Mar 2023 19:41:14 +0000 (19:41 +0000)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 19 Mar 2023 19:43:09 +0000 (19:43 +0000)
The test hangs forever on Python 3.7, no the gather() statement, and
wait_for() doesn't solve the problem.

tests/pool/test_null_pool_async.py
tests/pool/test_pool_async.py

index f3f16726bcea29ea513cf3e933b32acad2b24d6f..be29b3dcb61b14b7e9c5e4ab881330a4e82353f5 100644 (file)
@@ -841,6 +841,7 @@ async def test_stats_connect(dsn, proxy, monkeypatch):
         assert 200 <= stats["connections_ms"] < 300
 
 
+@pytest.mark.skipif("sys.version_info < (3, 8)", reason="asyncio bug")
 async def test_cancellation_in_queue(dsn):
     # https://github.com/psycopg/psycopg/issues/509
 
@@ -868,8 +869,7 @@ async def test_cancellation_in_queue(dsn):
                     if len(got_conns) >= nconns:
                         ev.set()
 
-                    while True:
-                        await asyncio.sleep(10)
+                    await asyncio.sleep(5)
 
             except BaseException as ex:
                 logging.info("worker %s stopped: %r", i, ex)
@@ -879,7 +879,7 @@ async def test_cancellation_in_queue(dsn):
         tasks = [asyncio.ensure_future(worker(i)) for i in range(nconns * 3)]
 
         # wait until the pool has served all the connections and clients are queued.
-        await ev.wait()
+        await asyncio.wait_for(ev.wait(), 3.0)
         for i in range(10):
             if p.get_stats().get("requests_queued", 0):
                 break
@@ -889,6 +889,7 @@ async def test_cancellation_in_queue(dsn):
             pytest.fail("no client got in the queue")
 
         [task.cancel() for task in reversed(tasks)]
+        # Python 3.7 hangs on this statement, instead of timing out or returning
         await asyncio.wait_for(asyncio.gather(*tasks, return_exceptions=True), 1.0)
 
         stats = p.get_stats()
index 668643ee7bc70daa812092c050392e321c11c140..83faf18dad2584d75eae3daa5bc6a94937c4a87c 100644 (file)
@@ -1176,6 +1176,7 @@ async def test_debug_deadlock(dsn):
         logger.setLevel(old_level)
 
 
+@pytest.mark.skipif("sys.version_info < (3, 8)", reason="asyncio bug")
 async def test_cancellation_in_queue(dsn):
     # https://github.com/psycopg/psycopg/issues/509
 
@@ -1201,8 +1202,7 @@ async def test_cancellation_in_queue(dsn):
                     if len(got_conns) >= nconns:
                         ev.set()
 
-                    while True:
-                        await asyncio.sleep(10)
+                    await asyncio.sleep(5)
 
             except BaseException as ex:
                 logging.info("worker %s stopped: %r", i, ex)
@@ -1212,7 +1212,7 @@ async def test_cancellation_in_queue(dsn):
         tasks = [asyncio.ensure_future(worker(i)) for i in range(nconns * 3)]
 
         # wait until the pool has served all the connections and clients are queued.
-        await ev.wait()
+        await asyncio.wait_for(ev.wait(), 3.0)
         for i in range(10):
             if p.get_stats().get("requests_queued", 0):
                 break
@@ -1222,6 +1222,7 @@ async def test_cancellation_in_queue(dsn):
             pytest.fail("no client got in the queue")
 
         [task.cancel() for task in reversed(tasks)]
+        # Python 3.7 hangs on this statement, instead of timing out or returning
         await asyncio.wait_for(asyncio.gather(*tasks, return_exceptions=True), 1.0)
 
         stats = p.get_stats()