Skip to content

Commit

Permalink
Testing: Check kernel restarts when external interpreters are killed
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Oct 15, 2020
1 parent e9793ab commit 26ebc2d
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -1608,35 +1608,55 @@ def test_conda_env_activation(ipyconsole, qtbot):


@flaky(max_runs=3)
@pytest.mark.parametrize("external_interpreter", [True, False])
@pytest.mark.skipif(os.name == 'nt', reason="no SIGTERM on Windows")
def test_kernel_kill(ipyconsole, qtbot):
def test_kernel_kill(ipyconsole, qtbot, external_interpreter):
"""
Test that the kernel correctly restarts after a kill.
"""
if external_interpreter:
if bool(os.environ.get('CI')):
CONF.set('main_interpreter', 'default', False)
CONF.set('main_interpreter', 'executable', get_conda_test_env())
ipyconsole.create_new_client()
else:
# We can't check this locally
return

shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)
# Wait for the restarter to start
qtbot.wait(3000)
crash_string = 'import os, signal; os.kill(os.getpid(), signal.SIGTERM)'

# Check only one comm is open
old_open_comms = list(shell.spyder_kernel_comm._comms.keys())
assert len(old_open_comms) == 1
with qtbot.waitSignal(shell.sig_prompt_ready, timeout=30000):
shell.execute(crash_string)
assert crash_string in shell._control.toPlainText()
assert "Restarting kernel..." in shell._control.toPlainText()

if not external_interpreter:
assert "Restarting kernel..." in shell._control.toPlainText()

# Check a new comm replaced the old one
new_open_comms = list(shell.spyder_kernel_comm._comms.keys())
assert len(new_open_comms) == 1
assert old_open_comms[0] != new_open_comms[0]

# Wait until the comm replies
qtbot.waitUntil(
lambda: shell.spyder_kernel_comm._comms[new_open_comms[0]][
'status'] == 'ready')
assert shell.spyder_kernel_comm._comms[new_open_comms[0]][
'status'] == 'ready'

# Reset interpreter
if external_interpreter:
CONF.set('main_interpreter', 'default', True)
CONF.set('main_interpreter', 'executable', '')


@flaky(max_runs=3)
def test_wrong_std_module(ipyconsole, qtbot):
Expand Down

0 comments on commit 26ebc2d

Please sign in to comment.