Skip to content

Commit ba026ec

Browse files
Tanmay DasPrabhakar Kumar
authored andcommitted
Introduce tests for MacOS
1 parent 17c6348 commit ba026ec

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

.github/workflows/run-tests.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ on:
1515

1616
jobs:
1717
node_tests:
18-
# If continue-on-error is set to true then all the queued jobs/steps
19-
# are executed regardless of failure
20-
# However, the workflow is always marked as passed even if some job
21-
# fails inside
22-
continue-on-error: ${{ inputs.continue-on-error }}
2318
strategy:
19+
# fail-fast=false runs all the jobs in strategy matrix
20+
# irrespective of failures in a particular job, and marks
21+
# the entire job as failed even if one job has failed
22+
fail-fast: false
2423
matrix:
25-
os: [ubuntu-latest, windows-latest]
24+
os: [ubuntu-latest, windows-latest, macos-latest]
2625
runs-on: ${{ matrix.os }}
2726
defaults:
2827
run:
@@ -51,10 +50,10 @@ jobs:
5150
continue-on-error: ${{ inputs.continue-on-error }}
5251
strategy:
5352
matrix:
54-
os: [ubuntu-latest, windows-latest]
53+
os: [ubuntu-latest, windows-latest, macos-latest]
5554
python-version: ['3.7', '3.8', '3.9', '3.10']
5655
exclude:
57-
- os: windows-latest
56+
- os: [windows-latest]
5857
# Python 3.7 in Windows does not run successfully
5958
python-version: '3.7'
6059
runs-on: ${{ matrix.os }}

tests/util/inf_loop.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2020-2022 The MathWorks, Inc.
2+
3+
import asyncio
4+
import os
5+
import sys
6+
import time
7+
8+
"""This file launches an asynchrnous infinite loop.
9+
Used for testing matlab_proxy/util/__init__.py/get_child_processes
10+
"""
11+
12+
process_no = int(sys.argv[1])
13+
14+
loop = asyncio.get_event_loop()
15+
16+
# Runs infinite loop asynchronously
17+
async def inf_loop(process_no):
18+
process_no += 1
19+
inf_loop_file_path = os.path.join(os.path.dirname(__file__), "inf_loop.py")
20+
cmd = [f"python {inf_loop_file_path} {process_no}"]
21+
_ = await asyncio.create_subprocess_shell(*cmd)
22+
while True:
23+
time.sleep(1)
24+
25+
26+
# Allows only one python process
27+
if process_no < 2:
28+
loop.run_until_complete(inf_loop(process_no))

tests/util/test_mw.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ def test_range_matlab_connector_ports():
510510
assert first_port + 1 == second_port
511511

512512

513+
@pytest.mark.skipif(
514+
system.is_windows() or system.is_mac(),
515+
reason="xvfb is not meant for windows and mac machines",
516+
)
513517
async def test_create_xvfb_process(loop):
514518
"""Test to check if more than 1 xvfb process can be created with -displayfd flag
515519

tests/util/test_util.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# Copyright (c) 2020-2022 The MathWorks, Inc.
2+
13
import asyncio
4+
import os
25

36
import psutil
47
from matlab_proxy import util
@@ -45,7 +48,12 @@ def test_prettify():
4548
async def test_get_child_processes(loop):
4649
"""Tests if child processes are returned"""
4750

48-
cmd = ["python"]
51+
# Python process exits before validating get_child_processes
52+
# in Mac machine, so an asynchronous infinite loop is launched as a
53+
# to keep it always running
54+
process_no = 1
55+
inf_path = os.path.join(os.path.dirname(__file__), "inf_loop.py")
56+
cmd = [f"python {inf_path} {process_no}"]
4957
proc = await asyncio.create_subprocess_shell(*cmd)
5058

5159
children = util.get_child_processes(proc)

0 commit comments

Comments
 (0)