1
1
# Copyright 2023-2024 The MathWorks, Inc.
2
2
3
- import asyncio
4
3
import os
5
4
import shutil
6
5
7
6
import integration_test_utils
8
- import psutil
7
+ import matlab_proxy . util . event_loop as mwi_event_loop
9
8
import pytest
10
9
import requests .exceptions
11
10
from matlab_proxy import settings as mwi_settings
@@ -24,7 +23,6 @@ def matlab_proxy_fixture(module_monkeypatch):
24
23
monkeypatch_module_scope (fixture): returns a MonkeyPatch object
25
24
available in module scope
26
25
"""
27
- import matlab_proxy .util
28
26
29
27
integration_test_utils .perform_basic_checks ()
30
28
@@ -51,14 +49,15 @@ def matlab_proxy_fixture(module_monkeypatch):
51
49
"MWI_APP_PORT" : mwi_app_port ,
52
50
"MWI_BASE_URL" : mwi_base_url ,
53
51
"MWI_LOG_FILE" : str (matlab_proxy_logs_path ),
52
+ "MWI_JUPYTER_LOG_LEVEL" : "WARN" ,
54
53
"MWI_ENABLE_TOKEN_AUTH" : "false" ,
55
54
}
56
55
57
56
# 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 ()
59
58
60
59
# Run matlab-proxy in the background in an event loop
61
- proc = loop .run_until_complete (
60
+ matlab_proxy_process = loop .run_until_complete (
62
61
integration_test_utils .start_matlab_proxy_app (input_env = input_env )
63
62
)
64
63
# Poll for matlab-proxy URL to respond
@@ -87,21 +86,15 @@ def matlab_proxy_fixture(module_monkeypatch):
87
86
# Run the jupyter kernel tests
88
87
yield
89
88
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"
100
93
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 ()
105
98
106
99
107
100
@pytest .fixture (scope = "module" , autouse = True )
0 commit comments