11# Copyright 2023-2024 The MathWorks, Inc.
22
3- import asyncio
43import os
54import shutil
65
76import integration_test_utils
8- import psutil
7+ import matlab_proxy . util . event_loop as mwi_event_loop
98import pytest
109import requests .exceptions
1110from 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 )
0 commit comments