Skip to content

Commit

Permalink
feat: set one docker per class
Browse files Browse the repository at this point in the history
  • Loading branch information
hlouzada committed Sep 30, 2024
1 parent a1dc91a commit dd89fc7
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 90 deletions.
1 change: 1 addition & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def run_pytest(run_slow=False, extra_args=None, remoteclient=False):
pytest_args += extra_args

if remoteclient:
pytest_args += ['--container-scope=class']
pytest_args += ['./spyder/plugins/remoteclient']
os.environ["SPYDER_TEST_REMOTE_CLIENT"] = "true"
else:
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/remoteclient/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def docker_compose_file(pytestconfig):
return str(HERE / "docker-compose.yml")


@pytest.fixture(scope="session")
@pytest.fixture(scope="class")
def remote_client_id(
ssh_server_addr: typing.Tuple[str, int], remote_client: RemoteClient
) -> typing.Iterator[SpyderRemoteClient]:
Expand Down Expand Up @@ -180,7 +180,7 @@ def ipyconsole_and_remoteclient() -> (
gc.collect()


@pytest.fixture(scope="session")
@pytest.fixture(scope="class")
def ssh_server_addr(
docker_ip: str, docker_services: Services
) -> typing.Tuple[str, int]:
Expand Down
176 changes: 88 additions & 88 deletions spyder/plugins/remoteclient/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,94 +14,94 @@
# Local imports
from spyder.plugins.remoteclient.tests.conftest import await_future


@flaky(max_runs=3, min_passes=1)
def test_shutdown_kernel(ipyconsole, remote_client, remote_client_id, qtbot):
"""Starts and stops a kernel on the remote server."""
remote_client.create_ipyclient_for_server(remote_client_id)
shell = ipyconsole.get_current_shellwidget()

qtbot.waitUntil(
lambda: shell.spyder_kernel_ready and shell._prompt_html is not None,
timeout=180000, # longer timeout for installation
)

ipyconsole.get_widget().close_client()

assert (
await_future(remote_client.get_kernels(remote_client_id), timeout=10)
== []
)


def test_restart_kernel(ipyconsole, remote_client, remote_client_id, qtbot):
"""Test that kernel is restarted correctly."""
remote_client.create_ipyclient_for_server(remote_client_id)
shell = ipyconsole.get_current_shellwidget()

qtbot.waitUntil(
lambda: shell.spyder_kernel_ready and shell._prompt_html is not None,
timeout=180000,
)

# Do an assignment to verify that it's not there after restarting
with qtbot.waitSignal(shell.executed):
shell.execute("a = 10")

# Restart kernel and wait until it's up again.
# NOTE: We trigger the restart_action instead of calling `restart_kernel`
# directly to also check that that action is working as expected and avoid
# regressions such as spyder-ide/spyder#22084.
shell._prompt_html = None
ipyconsole.get_widget().restart_action.trigger()
qtbot.waitUntil(
lambda: shell.spyder_kernel_ready and shell._prompt_html is not None,
timeout=4000,
)

assert not shell.is_defined("a")

with qtbot.waitSignal(shell.executed):
shell.execute("b = 10")

# Make sure that kernel is responsive after restart
qtbot.waitUntil(lambda: shell.is_defined("b"), timeout=2000)

ipyconsole.get_widget().close_client()


def test_kernel_kill(ipyconsole, remote_client, remote_client_id, qtbot):
"""Test that the kernel correctly restarts after a kill."""
crash_string = "import os, signal; os.kill(os.getpid(), signal.SIGTERM)"

remote_client.create_ipyclient_for_server(remote_client_id)
shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(
lambda: shell.spyder_kernel_ready and shell._prompt_html is not None,
timeout=180000,
)

# Since the heartbeat and the tunnels are running in separate threads, we
# need to make sure that the heartbeat thread has "higher" priority than
# the tunnel thread, otherwise the kernel will be restarted and the tunnels
# recreated before the heartbeat can detect the kernel is dead.
# In the test enviroment, the heartbeat needs to be set to a lower value
# because there are fewer threads running.
shell.kernel_handler.set_time_to_dead(0.2)

shell._prompt_html = None
with qtbot.waitSignal(shell.sig_prompt_ready, timeout=30000):
shell.execute(crash_string)

assert "The kernel died, restarting..." in shell._control.toPlainText()

with qtbot.waitSignal(shell.executed):
shell.execute("b = 10")

# Make sure that kernel is responsive after restart
qtbot.waitUntil(lambda: shell.is_defined("b"), timeout=2000)

ipyconsole.get_widget().close_client()
class TestIpythonConsole:
@flaky(max_runs=3, min_passes=1)
def test_shutdown_kernel(ipyconsole, remote_client, remote_client_id, qtbot):
"""Starts and stops a kernel on the remote server."""
remote_client.create_ipyclient_for_server(remote_client_id)
shell = ipyconsole.get_current_shellwidget()

qtbot.waitUntil(
lambda: shell.spyder_kernel_ready and shell._prompt_html is not None,
timeout=180000, # longer timeout for installation
)

ipyconsole.get_widget().close_client()

assert (
await_future(remote_client.get_kernels(remote_client_id), timeout=10)
== []
)


def test_restart_kernel(ipyconsole, remote_client, remote_client_id, qtbot):
"""Test that kernel is restarted correctly."""
remote_client.create_ipyclient_for_server(remote_client_id)
shell = ipyconsole.get_current_shellwidget()

qtbot.waitUntil(
lambda: shell.spyder_kernel_ready and shell._prompt_html is not None,
timeout=180000,
)

# Do an assignment to verify that it's not there after restarting
with qtbot.waitSignal(shell.executed):
shell.execute("a = 10")

# Restart kernel and wait until it's up again.
# NOTE: We trigger the restart_action instead of calling `restart_kernel`
# directly to also check that that action is working as expected and avoid
# regressions such as spyder-ide/spyder#22084.
shell._prompt_html = None
ipyconsole.get_widget().restart_action.trigger()
qtbot.waitUntil(
lambda: shell.spyder_kernel_ready and shell._prompt_html is not None,
timeout=4000,
)

assert not shell.is_defined("a")

with qtbot.waitSignal(shell.executed):
shell.execute("b = 10")

# Make sure that kernel is responsive after restart
qtbot.waitUntil(lambda: shell.is_defined("b"), timeout=2000)

ipyconsole.get_widget().close_client()


def test_kernel_kill(ipyconsole, remote_client, remote_client_id, qtbot):
"""Test that the kernel correctly restarts after a kill."""
crash_string = "import os, signal; os.kill(os.getpid(), signal.SIGTERM)"

remote_client.create_ipyclient_for_server(remote_client_id)
shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(
lambda: shell.spyder_kernel_ready and shell._prompt_html is not None,
timeout=180000,
)

# Since the heartbeat and the tunnels are running in separate threads, we
# need to make sure that the heartbeat thread has "higher" priority than
# the tunnel thread, otherwise the kernel will be restarted and the tunnels
# recreated before the heartbeat can detect the kernel is dead.
# In the test enviroment, the heartbeat needs to be set to a lower value
# because there are fewer threads running.
shell.kernel_handler.set_time_to_dead(0.2)

shell._prompt_html = None
with qtbot.waitSignal(shell.sig_prompt_ready, timeout=30000):
shell.execute(crash_string)

assert "The kernel died, restarting..." in shell._control.toPlainText()

with qtbot.waitSignal(shell.executed):
shell.execute("b = 10")

# Make sure that kernel is responsive after restart
qtbot.waitUntil(lambda: shell.is_defined("b"), timeout=2000)

ipyconsole.get_widget().close_client()


if __name__ == "__main__":
Expand Down

0 comments on commit dd89fc7

Please sign in to comment.