Skip to content

Commit

Permalink
Enhances the integration test framework to prevent stalling during th…
Browse files Browse the repository at this point in the history
…e teardown phase.
  • Loading branch information
pauldruce authored and Krishan Sharma committed Oct 22, 2024
1 parent e80432f commit cbe2303
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ licensing-logs
.yarn
src/jupyter_matlab_labextension/src/lezer-matlab/src/parser.js
src/jupyter_matlab_labextension/src/lezer-matlab/src/parser.terms.js
integ-tests.log
tests/integration/integ_logs.log
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ npm = ["jlpm"]
minversion = "6.0"
addopts = "-ra -q"
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
testpaths = ["tests"]
filterwarnings = ["ignore::DeprecationWarning", "ignore::RuntimeWarning"]

Expand Down
31 changes: 12 additions & 19 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Copyright 2023-2024 The MathWorks, Inc.

import asyncio
import os
import shutil

import integration_test_utils
import psutil
import matlab_proxy.util.event_loop as mwi_event_loop
import pytest
import requests.exceptions
from matlab_proxy import settings as mwi_settings
Expand All @@ -24,7 +23,6 @@ def matlab_proxy_fixture(module_monkeypatch):
monkeypatch_module_scope (fixture): returns a MonkeyPatch object
available in module scope
"""
import matlab_proxy.util

integration_test_utils.perform_basic_checks()

Expand All @@ -51,14 +49,15 @@ def matlab_proxy_fixture(module_monkeypatch):
"MWI_APP_PORT": mwi_app_port,
"MWI_BASE_URL": mwi_base_url,
"MWI_LOG_FILE": str(matlab_proxy_logs_path),
"MWI_JUPYTER_LOG_LEVEL": "WARN",
"MWI_ENABLE_TOKEN_AUTH": "false",
}

# Get event loop to start matlab-proxy in background
loop = matlab_proxy.util.get_event_loop()
loop = mwi_event_loop.get_event_loop()

# Run matlab-proxy in the background in an event loop
proc = loop.run_until_complete(
matlab_proxy_process = loop.run_until_complete(
integration_test_utils.start_matlab_proxy_app(input_env=input_env)
)
# Poll for matlab-proxy URL to respond
Expand Down Expand Up @@ -87,21 +86,15 @@ def matlab_proxy_fixture(module_monkeypatch):
# Run the jupyter kernel tests
yield

# Terminate matlab-proxy
timeout = 120
child_process = psutil.Process(proc.pid).children(recursive=True)
for process in child_process:
try:
process.terminate()
process.wait()
except Exception:
pass

# Request timeouts
timeout = 120 # seconds
# Send shutdown_integration request to MATLAB Proxy
shutdown_url = f"{matlab_proxy_url}/shutdown_integration"
try:
proc.terminate()
loop.run_until_complete(asyncio.wait_for(proc.wait(), timeout=timeout))
except Exception:
proc.kill()
requests.delete(shutdown_url, timeout=timeout)
except requests.exceptions.Timeout:
print("Timed out waiting for matlab-proxy to shutdown, killing process.")
matlab_proxy_process.kill()


@pytest.fixture(scope="module", autouse=True)
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/integration_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ async def start_matlab_proxy_app(input_env={}):
proc = await asyncio.create_subprocess_exec(
*cmd,
env=matlab_proxy_env,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
return proc

Expand Down

0 comments on commit cbe2303

Please sign in to comment.