]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: verify ctrl-c in async mode using get_event_loop
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 29 Apr 2022 23:16:02 +0000 (01:16 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 30 Apr 2022 00:49:14 +0000 (02:49 +0200)
tests/test_concurrency_async.py

index adc95ce3e33d5c70993c754be1fbf154a77b8523..88bdc7d419cd9d0c00a1c7eab7ba1c86a56d2aa5 100644 (file)
@@ -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"