Skip to content

Commit 34f1887

Browse files
pauldrucePrabhakar Kumar
authored and
Prabhakar Kumar
committed
Updates the e2e testing infrastructure to enable other licensing methods.
1 parent f3d4013 commit 34f1887

12 files changed

+798
-566
lines changed

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

+39-19
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

33
name: End-to-End Tests for Jupyter Integration for MATLAB
44
on:
@@ -7,6 +7,9 @@ on:
77
jobs:
88
playwright_e2e_tests:
99
runs-on: ubuntu-latest
10+
defaults:
11+
run:
12+
working-directory: tests/e2e
1013
env:
1114
NODE_VERSION: 18
1215
PYTHON_VERSION: 3.8
@@ -18,17 +21,20 @@ jobs:
1821
with:
1922
node-version: ${{ env.NODE_VERSION }}
2023

24+
- name: Set up Python
25+
uses: actions/setup-python@v4
26+
with:
27+
python-version: ${{ env.PYTHON_VERSION }}
28+
2129
- name: Install xvfb
2230
run: |
2331
sudo apt-get update
2432
sudo apt-get install -y xvfb
2533
2634
- name: Install node dependencies
27-
working-directory: ./tests/e2e
2835
run: npm ci
2936

3037
- name: Run the linter
31-
working-directory: ./tests/e2e
3238
run: npm run lint
3339

3440
- name: Set up MATLAB
@@ -37,45 +43,59 @@ jobs:
3743
with:
3844
products: MATLAB Symbolic_Math_Toolbox
3945

40-
- name: Set up Python
41-
uses: actions/setup-python@v4
42-
with:
43-
python-version: ${{ env.PYTHON_VERSION }}
46+
4447

4548
- name: Install jupyterlab and jupyter-matlab-proxy
49+
working-directory: ${{ github.workspace }}
4650
run: |
4751
python3 -m pip install --upgrade pip
48-
pip install ".[dev]"
49-
pip install "jupyterlab>3.1.0,<4.0.0"
52+
python3 -m pip install ".[dev]"
53+
python3 -m pip install "jupyterlab>3.1.0,<4.0.0"
5054
5155
- name: Install playwright browsers
52-
working-directory: ./tests/e2e
5356
run: npx playwright install --with-deps
5457

5558
- name: Find an available port
5659
run: |
57-
FREE_PORT=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()');
60+
FREE_PORT=$(python3 -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()');
5861
echo "Using port = ${FREE_PORT}"
5962
echo "TEST_JMP_PORT=$FREE_PORT" >> "$GITHUB_ENV"
6063
61-
# Playwright will start and stop the JupyterLab server, so we need
62-
# to activate the Python venv. The command that is executed by Playwright
63-
# is set by the webServer setting in the file playwright.config.ts
64-
- name: Run playwright tests
65-
working-directory: tests/e2e
64+
- name: Start JupyterLab in background and save PID
65+
id: start-jlab
66+
run: |
67+
npm start
68+
69+
- name: License MATLAB
6670
env:
6771
TEST_USERNAME: ${{ secrets.TEST_USERNAME }}
6872
TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }}
73+
run: |
74+
python3 -m pip install --upgrade pip
75+
python3 -m pip install pytest-playwright
76+
python3 -m playwright install
77+
python3 -c "from tests.utils.licensing import *; license_with_online_licensing(log_dir=\"./licensing-logs\")"
78+
79+
- name: Run playwright tests
80+
env:
6981
TEST_JMP_PORT: ${{ env.TEST_JMP_PORT }}
7082
run: |
7183
echo "Playwright version: $(npx playwright -V)"
72-
npx playwright test
84+
npm test
85+
86+
- name: Stop JupyterLab
87+
if: always()
88+
run: |
89+
npm stop
7390
7491
- name: Zip test results
7592
if: always()
76-
working-directory: tests/e2e
7793
run: |
78-
zip -r zipped-e2e-test-results.zip ./playwright-report ./test-results
94+
zip -r zipped-e2e-test-results.zip \
95+
./playwright-report \
96+
./test-results \
97+
./licensing-logs \
98+
./jupyterlab.log
7999
80100
- name: Preserve test results after the job has finished
81101
if: always()

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ playwright-report
1414
test-results
1515
.env
1616
.python-version
17+
jupyterlab.log
18+
jlab.pid
19+
licensing-logs

tests/README.md

+68-28
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,62 @@ a set of helpers and fixtures for JupyterLab UI exclusively in TypeScript.
102102
1. MATLAB (Version >= `R2020b`) in the system path
103103
2. NodeJS version 18 or higher.
104104
3. [MATLAB Proxy](https://github.com/mathworks/matlab-proxy) requirements
105-
4. MATLAB Proxy should be unlicensed
106-
6. Jupyter MATLAB Proxy requirements
107-
7. Valid MathWorks Account credentials
105+
4. Jupyter MATLAB Proxy requirements
106+
5. A way to license MATLAB
108107
109108
110-
### How to run the end-to-end tests
111-
* Set the environment variables TEST_USERNAME and TEST_PASSWORD to be your
112-
MathWorks Account user credentials
109+
### Run the end-to-end tests
110+
#### Licensing Information
111+
The end-to-end tests require a licensed MATLAB to function.
112+
113+
The simplest option is to ensure the MATLAB is licensed before you start the
114+
JupyterLab fixture, and set the environment variable
115+
`MWI_USE_EXISTING_LICENSE=true` before starting it.
116+
117+
Another option is to license the MATLAB using the jupyter-matlab-proxy interface
118+
manually or by using the helper methods provided.
119+
These helper methods license the MATLAB via the matlab-proxy interface using
120+
online licensing.
121+
This approach is suitable for automation and can be used in CI systems.
122+
See the GitHub Actions Workflows in this repository for an example of how to do this.
123+
124+
#### Setup
125+
* From the root directory of this project, install jupyter-matlab-proxy and
126+
JupyterLab:
127+
```
128+
pip install ".[dev]" "jupyterlab>=3.1.0,<4.0.0"
129+
```
130+
MathWorks recommends using a Python virtual environment such as venv or conda.
131+
* From this repository's directory `tests/e2e`, install the node packages:
132+
```
133+
npm install
134+
```
135+
or to use the exact package version in the package-lock.json, use the command
136+
`npm ci` instead.
137+
* Install the Playwright browsers:
138+
```
139+
npx playwright install
140+
```
141+
142+
#### Start the JupyterLab fixture
143+
The steps for starting the JupyterLab fixture depend on your licensing method.
144+
All steps assume you run them from the `tests/e2e` directory.
145+
146+
If you are using an already licensed MATLAB:
147+
- Ensure you set the environment variable `MWI_USE_EXISTING_LICENSE=true` before
148+
starting the JupyterLab instance.
149+
- Run the command `npm start`
150+
- Then run the tests: `npm test`
151+
152+
If you are going to license the MATLAB using online licensing after starting the JupyterLab instance
153+
- Start the JupyterLab fixture:
154+
```
155+
npm start
156+
```
157+
- License the MATLAB manually using the JupyterLab instance via the UI or by using the
158+
helper methods provided. The steps for using the helper methods is outlined:
159+
- Set the environment variables `TEST_USERNAME` and `TEST_PASSWORD` to your
160+
MathWorks Account user credentials
113161
- Using a `.env` file (recommended):
114162
- Create a file called `.env` at the base of this repository, with the
115163
following lines:
@@ -123,37 +171,29 @@ a set of helpers and fixtures for JupyterLab UI exclusively in TypeScript.
123171
```
124172
(if you don't want to use 'export' you can pass the environment
125173
variables in by prepending them to the Playwright test command below)
126-
- Powershell (Windows):
174+
- PowerShell (Windows):
127175
```powershell
128176
$env:TEST_USERNAME="some-username"; $env:TEST_PASSWORD="some-password"
129177
```
130-
* From the root directory of this project, install jupyter-matlab-proxy and
131-
JupyterLab with the command:
178+
- Use the helper functions provided:
132179
```
133-
pip install ".[dev]" "jupyterlab>=3.1.0,<4.0.0"
180+
python3 -m pip install pytest-playwright
181+
python3 -m playwright install
182+
python3 -c "from tests.utils.licensing import *; license_with_online_licensing()"
134183
```
135-
* From this repository's directory `/tests/e2e`, install the node packages using:
136-
```
137-
npm install
138-
```
139-
or to use the exact package version in the package-lock.json, use the command
140-
`npm ci` instead.
141-
* Install the Playwright browsers with the command:
142-
```
143-
npx playwright install
144-
```
145-
* Run the Playwright tests:
146-
```
147-
npx playwright test
148-
```
149-
If you don't want to use 'export' on your bash environment variables, you can pass in the
150-
variables like this:
184+
185+
#### Stop the JupyterLab Fixture
186+
* After testing has finished, stop the JupyterLab fixture by running the command
151187
```
152-
TEST_USERNAME="some-username" TEST_PASSWORD="some-password" npx playwright test
188+
npm stop
153189
```
190+
or by using the JupyterLab UI.
191+
192+
The default behaviour is for the logs of the JupyterLab instance to be written to
193+
a`jupyterlab.log` file in the `tests/e2e` directory.
154194
155195
----
156196
157-
Copyright 2023 The MathWorks, Inc.
197+
Copyright 2023-2024 The MathWorks, Inc.
158198
159199
----

tests/e2e/jupyter_server_test_config.py

+12-5
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

33
"""
44
JupyterLab Configuration
@@ -16,10 +16,17 @@
1616
is parsed by Jupyter and the below modifications to configuration class are
1717
applied.
1818
"""
19+
import os
20+
from tempfile import mkdtemp
1921

22+
# Allow JupyterLab to be started as root user
23+
c.ServerApp.allow_root = True
2024

21-
from tempfile import mkdtemp
25+
# Listen on all IP Addresses - JLab defaults to only allowing requests from localhost.
26+
c.ServerApp.ip = "0.0.0.0"
2227

28+
# Set the port to serve JupyterLab on.
29+
c.ServerApp.port = int(os.getenv("TEST_JMP_PORT", 8888))
2330

2431
# Disable port retries
2532
c.ServerApp.port_retries = 0
@@ -31,10 +38,10 @@
3138
c.ServerApp.root_dir = mkdtemp(prefix="galata-test-")
3239

3340
# Disable token-based authentication
34-
c.ServerApp.token = ""
41+
c.IdentityProvider.token = ""
3542

3643
# Disable password-based authentication
37-
c.ServerApp.password = ""
44+
c.IdentityProvider.password = ""
3845

3946
# Disable Cross-Site Request Forgery (CSRF) protection
4047
c.ServerApp.disable_check_xsrf = True
@@ -43,4 +50,4 @@
4350
c.LabApp.expose_app_in_browser = True
4451

4552
# Set the log level to ERROR
46-
c.Application.log_level = "ERROR"
53+
c.Application.log_level = "INFO"

0 commit comments

Comments
 (0)