From 9e4967ccc854fc17e6c083a146fa5a8d13a34684 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Mon, 14 Mar 2022 17:57:19 +0100 Subject: [PATCH] Test coroutine interrupt --- ipykernel/tests/test_async.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ipykernel/tests/test_async.py b/ipykernel/tests/test_async.py index 1266fa355..7569e496a 100644 --- a/ipykernel/tests/test_async.py +++ b/ipykernel/tests/test_async.py @@ -1,7 +1,7 @@ """Test async/await integration""" from distutils.version import LooseVersion as V -import sys +import time import pytest import IPython @@ -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) @@ -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)