From: Daniele Varrazzo Date: Fri, 29 Apr 2022 23:16:02 +0000 (+0200) Subject: test: verify ctrl-c in async mode using get_event_loop X-Git-Tag: 3.1~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=382c67480cb2417cd6b461bbc8f9e14d123aaf8a;p=thirdparty%2Fpsycopg.git test: verify ctrl-c in async mode using get_event_loop --- 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"