Skip to content

Commit 9e4967c

Browse files
committed
Test coroutine interrupt
1 parent 7283ccb commit 9e4967c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ipykernel/tests/test_async.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Test async/await integration"""
22

33
from distutils.version import LooseVersion as V
4-
import sys
4+
import time
55

66
import pytest
77
import IPython
@@ -46,8 +46,10 @@ def test_async_interrupt(asynclib, request):
4646
assert content["status"] == "ok", content
4747

4848
flush_channels(KC)
49+
wait_time = 5
50+
t0 = time.time()
4951
msg_id = KC.execute(
50-
f"print('begin'); import {asynclib}; await {asynclib}.sleep(5)"
52+
f"print('begin'); import {asynclib}; await {asynclib}.sleep({wait_time})"
5153
)
5254
busy = KC.get_iopub_msg(timeout=TIMEOUT)
5355
validate_message(busy, "status", msg_id)
@@ -61,7 +63,10 @@ def test_async_interrupt(asynclib, request):
6163

6264
KM.interrupt_kernel()
6365
reply = KC.get_shell_msg()["content"]
66+
t1 = time.time()
6467
assert reply["status"] == "error", reply
6568
assert reply["ename"] in {"CancelledError", "KeyboardInterrupt"}
69+
# interrupting should not wait for the coroutine execution to complete
70+
assert t1 - t0 < wait_time
6671

6772
flush_channels(KC)

0 commit comments

Comments
 (0)