Skip to content

Commit cbe2303

Browse files
pauldrucekrisctl
authored andcommitted
Enhances the integration test framework to prevent stalling during the teardown phase.
1 parent e80432f commit cbe2303

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ licensing-logs
2020
.yarn
2121
src/jupyter_matlab_labextension/src/lezer-matlab/src/parser.js
2222
src/jupyter_matlab_labextension/src/lezer-matlab/src/parser.terms.js
23+
integ-tests.log
24+
tests/integration/integ_logs.log

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ npm = ["jlpm"]
118118
minversion = "6.0"
119119
addopts = "-ra -q"
120120
asyncio_mode = "auto"
121+
asyncio_default_fixture_loop_scope = "function"
121122
testpaths = ["tests"]
122123
filterwarnings = ["ignore::DeprecationWarning", "ignore::RuntimeWarning"]
123124

tests/integration/conftest.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Copyright 2023-2024 The MathWorks, Inc.
22

3-
import asyncio
43
import os
54
import shutil
65

76
import integration_test_utils
8-
import psutil
7+
import matlab_proxy.util.event_loop as mwi_event_loop
98
import pytest
109
import requests.exceptions
1110
from matlab_proxy import settings as mwi_settings
@@ -24,7 +23,6 @@ def matlab_proxy_fixture(module_monkeypatch):
2423
monkeypatch_module_scope (fixture): returns a MonkeyPatch object
2524
available in module scope
2625
"""
27-
import matlab_proxy.util
2826

2927
integration_test_utils.perform_basic_checks()
3028

@@ -51,14 +49,15 @@ def matlab_proxy_fixture(module_monkeypatch):
5149
"MWI_APP_PORT": mwi_app_port,
5250
"MWI_BASE_URL": mwi_base_url,
5351
"MWI_LOG_FILE": str(matlab_proxy_logs_path),
52+
"MWI_JUPYTER_LOG_LEVEL": "WARN",
5453
"MWI_ENABLE_TOKEN_AUTH": "false",
5554
}
5655

5756
# Get event loop to start matlab-proxy in background
58-
loop = matlab_proxy.util.get_event_loop()
57+
loop = mwi_event_loop.get_event_loop()
5958

6059
# Run matlab-proxy in the background in an event loop
61-
proc = loop.run_until_complete(
60+
matlab_proxy_process = loop.run_until_complete(
6261
integration_test_utils.start_matlab_proxy_app(input_env=input_env)
6362
)
6463
# Poll for matlab-proxy URL to respond
@@ -87,21 +86,15 @@ def matlab_proxy_fixture(module_monkeypatch):
8786
# Run the jupyter kernel tests
8887
yield
8988

90-
# Terminate matlab-proxy
91-
timeout = 120
92-
child_process = psutil.Process(proc.pid).children(recursive=True)
93-
for process in child_process:
94-
try:
95-
process.terminate()
96-
process.wait()
97-
except Exception:
98-
pass
99-
89+
# Request timeouts
90+
timeout = 120 # seconds
91+
# Send shutdown_integration request to MATLAB Proxy
92+
shutdown_url = f"{matlab_proxy_url}/shutdown_integration"
10093
try:
101-
proc.terminate()
102-
loop.run_until_complete(asyncio.wait_for(proc.wait(), timeout=timeout))
103-
except Exception:
104-
proc.kill()
94+
requests.delete(shutdown_url, timeout=timeout)
95+
except requests.exceptions.Timeout:
96+
print("Timed out waiting for matlab-proxy to shutdown, killing process.")
97+
matlab_proxy_process.kill()
10598

10699

107100
@pytest.fixture(scope="module", autouse=True)

tests/integration/integration_test_utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ async def start_matlab_proxy_app(input_env={}):
7070
proc = await asyncio.create_subprocess_exec(
7171
*cmd,
7272
env=matlab_proxy_env,
73-
stdout=asyncio.subprocess.PIPE,
74-
stderr=asyncio.subprocess.PIPE,
7573
)
7674
return proc
7775

0 commit comments

Comments
 (0)