Skip to content

Commit 7ce4f66

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

File tree

3 files changed

+75
-55
lines changed

3 files changed

+75
-55
lines changed

.github/workflows/run-integration-tests.yml

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

33
# Workflow that contains jobs to test MATLAB Jupyter Integration
44
name: Integration testing MATLAB Jupyter Integration
55

66
on:
77
# Reusable workflow
8-
# Trigger on workflow call
98
workflow_call:
109

1110
jobs:
@@ -56,15 +55,11 @@ jobs:
5655
TEST_USERNAME: ${{secrets.TEST_USERNAME}}
5756
TEST_PASSWORD: ${{secrets.TEST_PASSWORD}}
5857

59-
- name: Copy Log File
58+
- name: Preserve test logs
6059
if: ${{ always() }}
61-
run: |
62-
cp ${{ github.workspace }}/tests/integration/integ_logs.log ${{ matrix.os }}${{ matrix.matlab-release }}${{ matrix.python-version }}.log
63-
64-
- name: Make logs files available for downloading
65-
if: ${{ always() }}
66-
uses: actions/upload-artifact@v3
60+
uses: actions/upload-artifact@v4
6761
with:
68-
name: MATLAB Proxy Integration Test Log File
69-
path: ${{ matrix.os }}${{ matrix.matlab-release }}${{ matrix.python-version }}.log
70-
retention-days: 7
62+
name: MATLAB Proxy Integration Test Log File ${{ matrix.os }} matlab-${{ matrix.matlab-release }} python-${{ matrix.python-version }}
63+
path: |
64+
tests/integration/integ_logs.log
65+
licensing-screenshot-failed.png

tests/integration/conftest.py

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

3+
import asyncio
34
import os
45
import shutil
6+
7+
import psutil
58
import integration_test_utils
69
import pytest
710
import requests
@@ -49,6 +52,7 @@ def matlab_proxy_fixture(module_monkeypatch):
4952
"MWI_APP_PORT": mwi_app_port,
5053
"MWI_BASE_URL": mwi_base_url,
5154
"MWI_LOG_FILE": str(matlab_proxy_logs_path),
55+
"MWI_ENABLE_TOKEN_AUTH": "false",
5256
}
5357

5458
# Get event loop to start matlab-proxy in background
@@ -83,8 +87,20 @@ def matlab_proxy_fixture(module_monkeypatch):
8387
yield
8488

8589
# Terminate matlab-proxy
86-
proc.terminate()
87-
loop.run_until_complete(proc.wait())
90+
timeout = 120
91+
child_process = psutil.Process(proc.pid).children(recursive=True)
92+
for process in child_process:
93+
try:
94+
process.terminate()
95+
process.wait()
96+
except Exception:
97+
pass
98+
99+
try:
100+
proc.terminate()
101+
loop.run_until_complete(asyncio.wait_for(proc.wait(), timeout=timeout))
102+
except Exception:
103+
proc.kill()
88104

89105

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

tests/integration/integration_test_utils.py

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 The MathWorks, Inc.
1+
# Copyright 2023-2024 The MathWorks, Inc.
22
# Utility functions for integration testing of jupyter-matlab-proxy
33

44
import asyncio
@@ -148,45 +148,54 @@ def license_matlab_proxy(matlab_proxy_url):
148148
TEST_PASSWORD = os.environ["TEST_PASSWORD"]
149149

150150
with sync_playwright() as playwright:
151-
browser = playwright.chromium.launch(headless=True)
152-
page = browser.new_page()
153-
page.goto(matlab_proxy_url)
154-
155-
# Find the MHLM licensing windows in matlab-proxy
156-
mhlm_div = page.locator("#MHLM")
157-
expect(
158-
mhlm_div,
159-
"Wait for MHLM licensing window to appear. This might fail if the MATLAB is already licensed",
160-
).to_be_visible(timeout=60000)
161-
162-
# The login iframe is present within the MHLM Div
163-
login_iframe = mhlm_div.frame_locator("#loginframe")
164-
165-
# Fills in the username textbox
166-
email_text_box = login_iframe.locator("#userId")
167-
expect(
168-
email_text_box,
169-
"Wait for email ID textbox to appear",
170-
).to_be_visible(timeout=20000)
171-
email_text_box.fill(TEST_USERNAME)
172-
email_text_box.press("Enter")
173-
174-
# Fills in the password textbox
175-
password_text_box = login_iframe.locator("#password")
176-
expect(password_text_box, "Wait for password textbox to appear").to_be_visible(
177-
timeout=20000
178-
)
179-
password_text_box.fill(TEST_PASSWORD)
180-
password_text_box.press("Enter")
181-
password_text_box.press("Enter")
182-
183-
# Verifies if licensing is successful by checking the status information
184-
status_info = page.get_by_text("Status Information")
185-
expect(
186-
status_info,
187-
"Verify if Licensing is successful. This might fail if incorrect credentials are provided",
188-
).to_be_visible(timeout=60000)
189-
browser.close()
151+
try:
152+
browser = playwright.chromium.launch(headless=True)
153+
page = browser.new_page()
154+
page.goto(matlab_proxy_url)
155+
156+
# Find the MHLM licensing windows in matlab-proxy
157+
mhlm_div = page.locator("#MHLM")
158+
expect(
159+
mhlm_div,
160+
"Wait for MHLM licensing window to appear. This might fail if the MATLAB is already licensed",
161+
).to_be_visible(timeout=60000)
162+
163+
# The login iframe is present within the MHLM Div
164+
login_iframe = mhlm_div.frame_locator("#loginframe")
165+
166+
# Fills in the username textbox
167+
email_text_box = login_iframe.locator("#userId")
168+
expect(
169+
email_text_box,
170+
"Wait for email ID textbox to appear",
171+
).to_be_visible(timeout=20000)
172+
email_text_box.fill(TEST_USERNAME)
173+
email_text_box.press("Enter")
174+
175+
# Fills in the password textbox
176+
password_text_box = login_iframe.locator("#password")
177+
expect(
178+
password_text_box, "Wait for password textbox to appear"
179+
).to_be_visible(timeout=20000)
180+
password_text_box.fill(TEST_PASSWORD)
181+
password_text_box.press("Enter")
182+
password_text_box.press("Enter")
183+
184+
# Verifies if licensing is successful by checking the status information
185+
status_info = page.get_by_text("Status Information")
186+
expect(
187+
status_info,
188+
"Verify if Licensing is successful. This might fail if incorrect credentials are provided",
189+
).to_be_visible(timeout=60000)
190+
except:
191+
# Grab screenshots
192+
log_dir = "./"
193+
file_name = "licensing-screenshot-failed.png"
194+
file_path = os.path.join(log_dir, file_name)
195+
os.makedirs(log_dir, exist_ok=True)
196+
page.screenshot(path=file_path)
197+
finally:
198+
browser.close()
190199

191200

192201
def unlicense_matlab_proxy(matlab_proxy_url):

0 commit comments

Comments
 (0)