Skip to content

Commit 12f7c1d

Browse files
authored
Add more serverapp tests (#1079)
* 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
1 parent f583a11 commit 12f7c1d

File tree

4 files changed

+96
-11
lines changed

4 files changed

+96
-11
lines changed

.github/workflows/integration-tests.yml

+4-8
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ jobs:
1717
uses: actions/checkout@v3
1818
- name: Base Setup
1919
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
20-
- name: Install the Python dependencies
21-
run: |
22-
pip install -e ".[test]"
23-
pip install pytest-github-actions-annotate-failures
24-
- name: List installed packages
25-
run: |
26-
pip freeze
27-
pip check
2820
- name: Run the tests
2921
run: |
3022
hatch run cov:integration
23+
- name: Coverage
24+
run: |
25+
pip install codecov
26+
codecov
3127
3228
integration_check: # This job does nothing and is only used for the branch protection
3329
if: always()

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ exclude_lines = [
152152
"def __repr__",
153153
"if self.debug:",
154154
"if settings.DEBUG",
155+
"if TYPE_CHECKING:",
155156
"raise AssertionError",
156157
"raise NotImplementedError",
157158
"if 0:",

tests/test_serverapp.py

+37-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44
import pathlib
5+
import warnings
56
from unittest.mock import patch
67

78
import pytest
@@ -10,7 +11,13 @@
1011
from traitlets.tests.utils import check_help_all_output
1112

1213
from jupyter_server.auth.security import passwd_check
13-
from jupyter_server.serverapp import JupyterPasswordApp, ServerApp, list_running_servers
14+
from jupyter_server.serverapp import (
15+
JupyterPasswordApp,
16+
ServerApp,
17+
ServerWebApplication,
18+
list_running_servers,
19+
random_ports,
20+
)
1421

1522

1623
def test_help_output():
@@ -401,3 +408,32 @@ def test_observed_root_dir_does_not_update_preferred_dir(tmp_path, jp_configurab
401408
app = jp_configurable_serverapp(root_dir=path, preferred_dir=path)
402409
app.root_dir = new_path
403410
assert app.preferred_dir == path
411+
412+
413+
def test_random_ports():
414+
ports = list(random_ports(500, 50))
415+
assert len(ports) == 50
416+
417+
418+
def test_server_web_application(jp_serverapp):
419+
server: ServerApp = jp_serverapp
420+
server.default_url = "/foo"
421+
with warnings.catch_warnings():
422+
warnings.simplefilter("ignore")
423+
app = ServerWebApplication(
424+
server,
425+
[],
426+
server.kernel_manager,
427+
server.contents_manager,
428+
server.session_manager,
429+
server.kernel_manager,
430+
server.config_manager,
431+
server.event_logger,
432+
["jupyter_server.gateway.handlers"],
433+
server.log,
434+
server.base_url,
435+
server.default_url,
436+
{},
437+
{},
438+
)
439+
app.init_handlers([], app.settings)

tests/unix_sockets/test_serverapp_integration.py

+54-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
import pytest
88

9-
from jupyter_server.serverapp import list_running_servers, shutdown_server
9+
from jupyter_server.serverapp import (
10+
JupyterServerListApp,
11+
JupyterServerStopApp,
12+
list_running_servers,
13+
shutdown_server,
14+
)
1015
from jupyter_server.utils import urlencode_unix_socket, urlencode_unix_socket_path
1116

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

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

66+
# Fake out stopping the server.
67+
app = JupyterServerStopApp(sock=str(jp_unix_socket_file))
68+
app.initialize([])
69+
app.shutdown_server = lambda _: True # type:ignore
70+
app._maybe_remove_unix_socket = lambda _: _ # type: ignore
71+
app.start()
72+
6173
subprocess.check_output(["jupyter-server", "stop", jp_unix_socket_file])
6274

6375
assert encoded_sock_path.encode() not in subprocess.check_output(["jupyter-server", "list"])
@@ -195,4 +207,44 @@ def test_shutdown_server(jp_environ):
195207
break
196208
except ConnectionRefusedError:
197209
time.sleep(0.1)
198-
p.wait()
210+
_cleanup_process(p)
211+
212+
213+
@pytest.mark.integration_test
214+
def test_jupyter_server_apps(jp_environ):
215+
216+
# Start a server in another process
217+
# Stop that server
218+
import subprocess
219+
220+
from jupyter_client.connect import LocalPortCache
221+
222+
port = LocalPortCache().find_available_port("localhost")
223+
p = subprocess.Popen(["jupyter-server", f"--port={port}"])
224+
servers = []
225+
while 1:
226+
servers = list(list_running_servers())
227+
if len(servers):
228+
break
229+
time.sleep(0.1)
230+
231+
app = JupyterServerListApp()
232+
app.initialize([])
233+
app.jsonlist = True
234+
app.start()
235+
app.jsonlist = False
236+
app.json = True
237+
app.start()
238+
app.json = False
239+
app.start()
240+
241+
app = JupyterServerStopApp()
242+
app.initialize([])
243+
app.port = port
244+
while 1:
245+
try:
246+
app.start()
247+
break
248+
except ConnectionRefusedError:
249+
time.sleep(0.1)
250+
_cleanup_process(p)

0 commit comments

Comments
 (0)