Skip to content

Commit 0c9582a

Browse files
pauldrucePrabhakar Kumar
authored andcommitted
Fixing stalls in integration tests.
1 parent f9c390d commit 0c9582a

File tree

10 files changed

+130
-64
lines changed

10 files changed

+130
-64
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ htmlcov/
1212
.python-version
1313
coverage.xml
1414
.ipynb_checkpoints/
15-
*.ipynb
15+
*.ipynb
16+
.env

gui/package-lock.json

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def run(self):
5353
"pytest",
5454
"pytest-env",
5555
"pytest-cov",
56+
"pytest-timeout",
5657
"pytest-mock",
5758
"pytest-aiohttp",
5859
"psutil",

tests/integration/integration_tests_utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
import urllib3
99
import requests
1010
import json
11-
from logging_util import create_test_logger
11+
from logging_util import create_integ_test_logger
1212

13-
_logger = create_test_logger(
14-
__name__, log_file_path=os.getenv("MWI_INTEG_TESTS_LOG_FILE_PATH")
15-
)
13+
_logger = create_integ_test_logger(__name__)
1614

1715

1816
def perform_basic_checks():
@@ -22,6 +20,7 @@ def perform_basic_checks():
2220
"""
2321
import matlab_proxy.settings
2422

23+
_logger.info("Performing basic checks for matlab-proxy")
2524
# Validate MATLAB before testing
2625
_, matlab_path = matlab_proxy.settings.get_matlab_executable_and_root_path()
2726

@@ -63,6 +62,7 @@ async def start_matlab_proxy_app(out=asyncio.subprocess.PIPE, input_env={}):
6362
"""
6463
from matlab_proxy.util import system
6564

65+
_logger.info("Starting MATLAB Proxy app")
6666
cmd = matlab_proxy_cmd_for_testing()
6767
matlab_proxy_env = os.environ.copy()
6868
matlab_proxy_env.update(input_env)
@@ -73,7 +73,7 @@ async def start_matlab_proxy_app(out=asyncio.subprocess.PIPE, input_env={}):
7373
stdout=out,
7474
stderr=out,
7575
)
76-
76+
_logger.debug("MATLAB Proxy App started")
7777
return proc
7878

7979

@@ -110,6 +110,7 @@ def wait_matlab_proxy_ready(matlab_proxy_url):
110110
from matlab_proxy.util import system
111111
import matlab_proxy.settings as settings
112112

113+
_logger.info("Wait for MATLAB Proxy to start")
113114
# Wait until the matlab config file is created
114115
MAX_TIMEOUT = settings.get_process_startup_timeout()
115116
start_time = time.time()
@@ -175,6 +176,7 @@ def license_matlab_proxy(matlab_proxy_url):
175176
"""
176177
from playwright.sync_api import sync_playwright, expect
177178

179+
_logger.info("Licensing MATLAB using matlab-proxy")
178180
# These are MathWorks Account credentials to license MATLAB
179181
# Throws 'KeyError' if the following environment variables are not set
180182
TEST_USERNAME = os.environ["TEST_USERNAME"]
@@ -221,7 +223,7 @@ def license_matlab_proxy(matlab_proxy_url):
221223
status_info,
222224
"Verify if Licensing is successful. This might fail if incorrect credentials are provided",
223225
).to_be_visible(timeout=60000)
224-
226+
_logger.debug("Succeeded in licensing MATLAB using matlab-proxy")
225227
browser.close()
226228

227229

@@ -234,6 +236,7 @@ def unlicense_matlab_proxy(matlab_proxy_url):
234236
"""
235237
import warnings
236238

239+
_logger.info("Unlicensing matlab-proxy")
237240
max_retries = 3 # Max retries for unlicensing matlab-proxy
238241
retries = 0
239242

@@ -257,6 +260,7 @@ def unlicense_matlab_proxy(matlab_proxy_url):
257260
f"matlab-proxy is unlicensed but with error: {data['error']}",
258261
UserWarning,
259262
)
263+
_logger.debug("Succeeded in unlicensing matlab-proxy")
260264
break
261265
else:
262266
resp.raise_for_status()

tests/integration/integration_tests_with_license/conftest.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
import shutil
88
from matlab_proxy.util import system
99
from matlab_proxy.util.mwi import environment_variables as mwi_env
10-
from logging_util import create_test_logger
10+
from logging_util import create_integ_test_logger
1111

12-
_logger = create_test_logger(
13-
__name__, log_file_path=os.getenv("MWI_INTEG_TESTS_LOG_FILE_PATH")
14-
)
12+
_logger = create_integ_test_logger(__name__)
1513

1614

1715
@pytest.fixture(scope="module", name="module_monkeypatch")
@@ -40,9 +38,11 @@ def matlab_config_cleanup_fixture(request):
4038
"""
4139

4240
def delete_matlab_test_dir():
41+
_logger.debug("Cleaning up matlab config file")
4342
# Delete matlab_config_file & its owning directory
4443
matlab_config_file = utils.get_matlab_config_file()
4544
matlab_config_dir = os.path.dirname(matlab_config_file)
45+
_logger.debug("Deleting matlab test dir: " + matlab_config_dir)
4646
try:
4747
shutil.rmtree(matlab_config_dir)
4848
except FileNotFoundError:
@@ -73,6 +73,7 @@ def matlab_proxy_fixture(module_monkeypatch, request):
7373
import matlab_proxy.util
7474
from urllib.parse import urlparse
7575

76+
_logger.info("Starting MATLAB Proxy fixture")
7677
utils.perform_basic_checks()
7778

7879
# Select a random free port to serve matlab-proxy for testing
@@ -92,10 +93,10 @@ def matlab_proxy_fixture(module_monkeypatch, request):
9293

9394
# Run matlab-proxy in the background in an event loop
9495
proc = loop.run_until_complete(utils.start_matlab_proxy_app(input_env=input_env))
95-
_logger.info("Started MATLAB Proxy process")
96+
_logger.debug("Started MATLAB Proxy process")
9697

9798
utils.wait_server_info_ready(mwi_app_port)
98-
_logger.info("Server file is available")
99+
_logger.debug("Server file is available")
99100

100101
matlab_proxy_url = utils.get_connection_string(mwi_app_port)
101102

@@ -109,30 +110,34 @@ def matlab_proxy_fixture(module_monkeypatch, request):
109110
requests.exceptions.SSLError,
110111
),
111112
)
112-
_logger.info("MATLAB proxy URL responded")
113+
_logger.debug("MATLAB proxy URL responded")
113114

114115
# License matlab-proxy using playwright UI automation
115116
utils.license_matlab_proxy(matlab_proxy_url)
116-
_logger.info("Successfully licensed MATLAB Proxy")
117+
_logger.debug("Successfully licensed MATLAB via MATLAB Proxy")
117118

119+
# TODO: this is this block required?
118120
# Wait for matlab-proxy to be up and running
119121
utils.wait_matlab_proxy_ready(matlab_proxy_url)
120-
_logger.info("MATLAB Proxy is ready")
122+
_logger.debug("MATLAB Proxy is up and running")
121123

124+
_logger.debug("Copying matlab proxy config for reuse in tests")
122125
# Get the location of ".matlab"
123126
matlab_config_file = str(
124127
utils.get_matlab_config_file()
125128
) # ~/.matlab/MWI/proxy_app_config.json
126-
127129
dotmatlab_dir_path = os.path.dirname(os.path.dirname(matlab_config_file))
128-
129130
# Create a temporary location in .matlab directory
130131
temp_dir_path = os.path.join(dotmatlab_dir_path, "temp_dir")
131132
os.mkdir(temp_dir_path) # delete this folder after the test execution
132133
shutil.move(matlab_config_file, temp_dir_path)
133134

135+
_logger.debug("Terminating the setup+licensing matlab-proxy process")
134136
proc.terminate()
135137
loop.run_until_complete(proc.wait())
136138

137139
# Run the matlab proxy tests
140+
_logger.info("Finished licensing MATLAB for use in integration tests")
138141
yield
142+
143+
_logger.debug("Deleting matlab test directory")

0 commit comments

Comments
 (0)