Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test coroutine interrupt #880

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ipykernel/tests/test_async.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test async/await integration"""

import time

import pytest

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

flush_channels(KC)
msg_id = KC.execute(f"print('begin'); import {asynclib}; await {asynclib}.sleep(5)")
wait_time = 5
t0 = time.time()
msg_id = KC.execute(f"print('begin'); import {asynclib}; await {asynclib}.sleep({wait_time})")
busy = KC.get_iopub_msg(timeout=TIMEOUT)
validate_message(busy, "status", msg_id)
assert busy["content"]["execution_state"] == "busy"
Expand All @@ -56,7 +60,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)
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ test = [
"pytest-cov",
"flaky",
"ipyparallel",
"trio",
"curio",
"pre-commit",
"pytest-asyncio",
"pytest-timeout"
Expand Down