Skip to content

Commit d7e0056

Browse files
committed
Fix flaky server tests.
Force stop the jupyter server when the test is done to avoid it sticking around. Force test_user_client to use a free port instead of a potentially in use one. http://b/277579939 http://b/277898785
1 parent fc6e4db commit d7e0056

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

tests/test_jupyterlab_lsp.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import unittest
33

44
from jupyter_server.serverapp import ServerApp
5+
import subprocess
56

67
# Adapted from:
78
# https://github.com/jupyter-lsp/jupyterlab-lsp/blob/ce76fab170feea506faf9ef47e4bd6a468c24313/python_packages/jupyter_lsp/jupyter_lsp/tests/test_extension.py
@@ -30,3 +31,7 @@ def test_serverextension(self):
3031
self.assertTrue(found_lsp, "didn't install the /lsp/ route")
3132
app.stop()
3233

34+
strpid=subprocess.Popen("ps -ef | grep jupyter | grep 9999 | awk '{print $2}' | head -n 1", shell=True, stdout=subprocess.PIPE).stdout.read().decode("utf-8").strip()
35+
if strpid != "":
36+
pid=int(strpid)
37+
os.kill(pid, 9)

tests/test_user_secrets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def do_POST(s):
4040

4141

4242
class TestUserSecrets(unittest.TestCase):
43-
SERVER_ADDRESS = urlparse(os.getenv(_KAGGLE_URL_BASE_ENV_VAR_NAME, default="http://127.0.0.1:8001"))
43+
SERVER_ADDRESS = urlparse(os.getenv(_KAGGLE_URL_BASE_ENV_VAR_NAME, default="http://127.0.0.1:0"))
4444

4545
def _test_client(self, client_func, expected_path, expected_body, secret=None, success=True):
4646
_request = {}

0 commit comments

Comments
 (0)