From ac1c8d80e4796d22c0110cd54bc87ad4d5a9dc10 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 19 Mar 2023 19:41:14 +0000 Subject: [PATCH] test(pool): skip cancellation tests on Python 3.7 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 | 7 ++++--- tests/pool/test_pool_async.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/pool/test_null_pool_async.py b/tests/pool/test_null_pool_async.py index f3f16726b..be29b3dcb 100644 --- a/tests/pool/test_null_pool_async.py +++ b/tests/pool/test_null_pool_async.py @@ -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() diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index 668643ee7..83faf18da 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -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() -- 2.47.2