From 382c67480cb2417cd6b461bbc8f9e14d123aaf8a Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 30 Apr 2022 01:16:02 +0200 Subject: [PATCH] test: verify ctrl-c in async mode using get_event_loop --- tests/test_concurrency_async.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_concurrency_async.py b/tests/test_concurrency_async.py index adc95ce3e..88bdc7d41 100644 --- a/tests/test_concurrency_async.py +++ b/tests/test_concurrency_async.py @@ -157,22 +157,27 @@ async def test_identify_closure(dsn): await conn2.close() -@pytest.mark.xfail(reason="fix #231 for async connection") @pytest.mark.slow @pytest.mark.subprocess +@pytest.mark.skipif( + sys.platform == "win32", reason="don't know how to Ctrl-C on Windows" +) async def test_ctrl_c(dsn): script = f"""\ +import signal import asyncio import psycopg ctrl_c = False async def main(): + loop = asyncio.get_event_loop() async with await psycopg.AsyncConnection.connect({dsn!r}) as conn: + loop.add_signal_handler(signal.SIGINT, conn.cancel) cur = conn.cursor() try: await cur.execute("select pg_sleep(2)") - except KeyboardInterrupt: + except psycopg.errors.QueryCanceled: ctrl_c = True assert ctrl_c, "ctrl-c not received" -- 2.47.2