Skip to content

Commit

Permalink
Add more serverapp tests (jupyter-server#1079)
Browse files Browse the repository at this point in the history
* add more serverapp tests

* try again

* try to isolate failure

* try isolating stop app

* try again

* try again

* another debug

* try again

* try again

* try again

* try again

* try again

* try again

* try again
  • Loading branch information
blink1073 authored Nov 21, 2022
1 parent f583a11 commit 12f7c1d
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 11 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ jobs:
uses: actions/checkout@v3
- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- name: Install the Python dependencies
run: |
pip install -e ".[test]"
pip install pytest-github-actions-annotate-failures
- name: List installed packages
run: |
pip freeze
pip check
- name: Run the tests
run: |
hatch run cov:integration
- name: Coverage
run: |
pip install codecov
codecov
integration_check: # This job does nothing and is only used for the branch protection
if: always()
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ exclude_lines = [
"def __repr__",
"if self.debug:",
"if settings.DEBUG",
"if TYPE_CHECKING:",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
Expand Down
38 changes: 37 additions & 1 deletion tests/test_serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import pathlib
import warnings
from unittest.mock import patch

import pytest
Expand All @@ -10,7 +11,13 @@
from traitlets.tests.utils import check_help_all_output

from jupyter_server.auth.security import passwd_check
from jupyter_server.serverapp import JupyterPasswordApp, ServerApp, list_running_servers
from jupyter_server.serverapp import (
JupyterPasswordApp,
ServerApp,
ServerWebApplication,
list_running_servers,
random_ports,
)


def test_help_output():
Expand Down Expand Up @@ -401,3 +408,32 @@ def test_observed_root_dir_does_not_update_preferred_dir(tmp_path, jp_configurab
app = jp_configurable_serverapp(root_dir=path, preferred_dir=path)
app.root_dir = new_path
assert app.preferred_dir == path


def test_random_ports():
ports = list(random_ports(500, 50))
assert len(ports) == 50


def test_server_web_application(jp_serverapp):
server: ServerApp = jp_serverapp
server.default_url = "/foo"
with warnings.catch_warnings():
warnings.simplefilter("ignore")
app = ServerWebApplication(
server,
[],
server.kernel_manager,
server.contents_manager,
server.session_manager,
server.kernel_manager,
server.config_manager,
server.event_logger,
["jupyter_server.gateway.handlers"],
server.log,
server.base_url,
server.default_url,
{},
{},
)
app.init_handlers([], app.settings)
56 changes: 54 additions & 2 deletions tests/unix_sockets/test_serverapp_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

import pytest

from jupyter_server.serverapp import list_running_servers, shutdown_server
from jupyter_server.serverapp import (
JupyterServerListApp,
JupyterServerStopApp,
list_running_servers,
shutdown_server,
)
from jupyter_server.utils import urlencode_unix_socket, urlencode_unix_socket_path

# Skip this module if on Windows. Unix sockets are not available on Windows.
Expand Down Expand Up @@ -58,6 +63,13 @@ def test_shutdown_sock_server_integration(jp_unix_socket_file):

assert encoded_sock_path.encode() in subprocess.check_output(["jupyter-server", "list"])

# Fake out stopping the server.
app = JupyterServerStopApp(sock=str(jp_unix_socket_file))
app.initialize([])
app.shutdown_server = lambda _: True # type:ignore
app._maybe_remove_unix_socket = lambda _: _ # type: ignore
app.start()

subprocess.check_output(["jupyter-server", "stop", jp_unix_socket_file])

assert encoded_sock_path.encode() not in subprocess.check_output(["jupyter-server", "list"])
Expand Down Expand Up @@ -195,4 +207,44 @@ def test_shutdown_server(jp_environ):
break
except ConnectionRefusedError:
time.sleep(0.1)
p.wait()
_cleanup_process(p)


@pytest.mark.integration_test
def test_jupyter_server_apps(jp_environ):

# Start a server in another process
# Stop that server
import subprocess

from jupyter_client.connect import LocalPortCache

port = LocalPortCache().find_available_port("localhost")
p = subprocess.Popen(["jupyter-server", f"--port={port}"])
servers = []
while 1:
servers = list(list_running_servers())
if len(servers):
break
time.sleep(0.1)

app = JupyterServerListApp()
app.initialize([])
app.jsonlist = True
app.start()
app.jsonlist = False
app.json = True
app.start()
app.json = False
app.start()

app = JupyterServerStopApp()
app.initialize([])
app.port = port
while 1:
try:
app.start()
break
except ConnectionRefusedError:
time.sleep(0.1)
_cleanup_process(p)

0 comments on commit 12f7c1d

Please sign in to comment.