Skip to content

Commit

Permalink
test: verify ctrl-c in async mode using get_event_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
dvarrazzo committed Apr 30, 2022
1 parent e0a0ba2 commit 382c674
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/test_concurrency_async.py
Expand Up @@ -157,22 +157,27 @@ async def closer():
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"
Expand Down

0 comments on commit 382c674

Please sign in to comment.