Skip to content

Commit

Permalink
Merge pull request #532 from Carreau/split-sleep
Browse files Browse the repository at this point in the history
PR: Split `test_interrupt` into two tests
  • Loading branch information
ccordoba12 authored Feb 19, 2025
2 parents 633c297 + ab01e3b commit 2793fd3
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions spyder_kernels/console/tests/test_console_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ def test_debug_namespace(tmpdir):
break


def test_interrupt():
def test_interrupt_short_loop():
"""
Test that the kernel can be interrupted by calling a comm handler.
"""
Expand All @@ -1321,17 +1321,35 @@ def test_interrupt():
kernel_comm.remote_call().raise_interrupt_signal()
# Wait for shell message
while True:
assert time.time() - t0 < 5
delta = time.time() - t0
assert delta < 5
msg = client.get_shell_msg(timeout=TIMEOUT)
if msg["parent_header"].get("msg_id") != msg_id:
# not from my request
continue
break
assert time.time() - t0 < 5
delta = time.time() - t0
assert delta < 5, (
"10 seconds long call should have been interrupted, so the "
"interrupt signal was likely mishandled"
)


@pytest.mark.skipif(os.name == "nt", reason="Windows doesn't do 'interrupting sleep'")
def test_interrupt_long_sleep():
# Command to start the kernel
cmd = "from spyder_kernels.console import start; start.main()"
with setup_kernel(cmd) as client:
kernel_comm = CommBase()

# Create new comm and send the highest protocol
comm = Comm(kernel_comm._comm_name, client)
comm.open(data={})
comm._send_channel = client.control_channel
kernel_comm._register_comm(comm)

client.execute_interactive("import time", timeout=TIMEOUT)

if os.name == 'nt':
# Windows doesn't do "interrupting sleep"
return

# Try interrupting sleep
t0 = time.time()
Expand Down

0 comments on commit 2793fd3

Please sign in to comment.