Skip to content

Commit 2793fd3

Browse files
authored
Merge pull request spyder-ide#532 from Carreau/split-sleep
PR: Split `test_interrupt` into two tests
2 parents 633c297 + ab01e3b commit 2793fd3

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

spyder_kernels/console/tests/test_console_kernel.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ def test_debug_namespace(tmpdir):
12961296
break
12971297

12981298

1299-
def test_interrupt():
1299+
def test_interrupt_short_loop():
13001300
"""
13011301
Test that the kernel can be interrupted by calling a comm handler.
13021302
"""
@@ -1321,17 +1321,35 @@ def test_interrupt():
13211321
kernel_comm.remote_call().raise_interrupt_signal()
13221322
# Wait for shell message
13231323
while True:
1324-
assert time.time() - t0 < 5
1324+
delta = time.time() - t0
1325+
assert delta < 5
13251326
msg = client.get_shell_msg(timeout=TIMEOUT)
13261327
if msg["parent_header"].get("msg_id") != msg_id:
13271328
# not from my request
13281329
continue
13291330
break
1330-
assert time.time() - t0 < 5
1331+
delta = time.time() - t0
1332+
assert delta < 5, (
1333+
"10 seconds long call should have been interrupted, so the "
1334+
"interrupt signal was likely mishandled"
1335+
)
1336+
1337+
1338+
@pytest.mark.skipif(os.name == "nt", reason="Windows doesn't do 'interrupting sleep'")
1339+
def test_interrupt_long_sleep():
1340+
# Command to start the kernel
1341+
cmd = "from spyder_kernels.console import start; start.main()"
1342+
with setup_kernel(cmd) as client:
1343+
kernel_comm = CommBase()
1344+
1345+
# Create new comm and send the highest protocol
1346+
comm = Comm(kernel_comm._comm_name, client)
1347+
comm.open(data={})
1348+
comm._send_channel = client.control_channel
1349+
kernel_comm._register_comm(comm)
1350+
1351+
client.execute_interactive("import time", timeout=TIMEOUT)
13311352

1332-
if os.name == 'nt':
1333-
# Windows doesn't do "interrupting sleep"
1334-
return
13351353

13361354
# Try interrupting sleep
13371355
t0 = time.time()

0 commit comments

Comments
 (0)