Skip to content

Commit

Permalink
Test coroutine interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Mar 14, 2022
1 parent 7283ccb commit 9e4967c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ipykernel/tests/test_async.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test async/await integration"""

from distutils.version import LooseVersion as V
import sys
import time

import pytest
import IPython
Expand Down Expand Up @@ -46,8 +46,10 @@ def test_async_interrupt(asynclib, request):
assert content["status"] == "ok", content

flush_channels(KC)
wait_time = 5
t0 = time.time()
msg_id = KC.execute(
f"print('begin'); import {asynclib}; await {asynclib}.sleep(5)"
f"print('begin'); import {asynclib}; await {asynclib}.sleep({wait_time})"
)
busy = KC.get_iopub_msg(timeout=TIMEOUT)
validate_message(busy, "status", msg_id)
Expand All @@ -61,7 +63,10 @@ def test_async_interrupt(asynclib, request):

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

flush_channels(KC)

0 comments on commit 9e4967c

Please sign in to comment.