Skip to content

Commit fdd301d

Browse files
committed
Test coroutine interrupt
1 parent 828e55c commit fdd301d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ipykernel/tests/test_async.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Test async/await integration"""
22

3+
import time
4+
35
import pytest
46

57
from .test_message_spec import validate_message
@@ -43,7 +45,9 @@ def test_async_interrupt(asynclib, request):
4345
assert content["status"] == "ok", content
4446

4547
flush_channels(KC)
46-
msg_id = KC.execute(f"print('begin'); import {asynclib}; await {asynclib}.sleep(5)")
48+
wait_time = 5
49+
t0 = time.time()
50+
msg_id = KC.execute(f"print('begin'); import {asynclib}; await {asynclib}.sleep({wait_time})")
4751
busy = KC.get_iopub_msg(timeout=TIMEOUT)
4852
validate_message(busy, "status", msg_id)
4953
assert busy["content"]["execution_state"] == "busy"
@@ -56,7 +60,10 @@ def test_async_interrupt(asynclib, request):
5660

5761
KM.interrupt_kernel()
5862
reply = KC.get_shell_msg()["content"]
63+
t1 = time.time()
5964
assert reply["status"] == "error", reply
6065
assert reply["ename"] in {"CancelledError", "KeyboardInterrupt"}
66+
# interrupting should not wait for the coroutine execution to complete
67+
assert t1 - t0 < wait_time
6168

6269
flush_channels(KC)

0 commit comments

Comments
 (0)