Skip to content

Commit 8258dbc

Browse files
committed
Update file
1 parent 69d39c2 commit 8258dbc

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

AzureDevOps/DistributeTests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
We search for specific type of file structure (in this example test*), and slice them according to agent number
77
If we encounter multiple files [file1..file10] and if we have 2 agents, agent1 executes tests odd number of files while agent2 executes even number of files
88
For detalied slicing info: https://docs.microsoft.com/en-us/vsts/pipelines/test/parallel-testing-any-test-runner
9-
We use JUnit style test results to publish the test reports.
109
#>
1110

1211
$tests = Get-ChildItem .\tests\ -File # search for test files with specific pattern.
@@ -38,7 +37,7 @@ For ($i=$agentNumber; $i -le $testCount;) {
3837
$i = $i + $totalAgents
3938
}
4039

41-
# join all test files seperated by space. pytest runs multiple test files in following format pytest test1.py test2.py test3.py
40+
# join all test files seperated by space.
4241
$testFiles = $testsToRun -Join " "
4342
Write-Host "Test files $testFiles"
4443
# write these files into variable so that we can run them using pytest in subsequent task.

AzureDevOps/DistributeTests.sh

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
#!/usr/bin/env bash
2-
# Distribute tests across multiple agents for parallel execution (Bash version)
3-
# Produces MATLAB cell array like:
4-
# {'/path/to/file1.m','/path/to/file2.m'}
1+
#!/bin/bash
2+
#===============================================================================
3+
#
4+
# FILE: distribute_tests.sh
5+
#
6+
# USAGE: ./distribute_tests.sh
7+
#
8+
# DESCRIPTION: This script slices tests files across multiple agents for faster execution.
9+
# We search for specific type of file structure (in this example test*), and slice them according to agent number
10+
# If we encounter multiple files [file1..file10] and if we have 2 agents, agent1 executes tests odd number of files while agent2 executes even number of files
11+
#
12+
#===============================================================================
513

6-
# Find all test files (*.m) under ./tests
7-
# mapfile -t tests < <(find ./tests -type f -name "*.m" | sort) mapfile doesnt work on macOS bash 3.2
814
tests=()
915
while IFS= read -r file; do
1016
tests+=("$file")
1117
done < <(find ./tests -type f -name "*.m" | sort)
1218

13-
# Use Azure DevOps variables if available, else default to 1
14-
totalAgents=${SYSTEM_TOTALJOBSINPHASE:-1}
15-
agentNumber=${SYSTEM_JOBPOSITIONINPHASE:-1}
19+
# Use Azure DevOps variables
20+
totalAgents=${SYSTEM_TOTALJOBSINPHASE}
21+
agentNumber=${SYSTEM_JOBPOSITIONINPHASE}
1622
testCount=${#tests[@]}
1723

18-
# If not set or zero, default to 1
19-
if [[ -z "$totalAgents" || "$totalAgents" -eq 0 ]]; then
24+
if [ $totalAgents -eq 0 ]; then
2025
totalAgents=1
2126
fi
22-
if [[ -z "$agentNumber" || "$agentNumber" -eq 0 ]]; then
27+
# below conditions are used if parallel pipeline is not used. i.e. pipeline is running with single agent (no parallel configuration)
28+
if [ -z $agentNumber ]; then
2329
agentNumber=1
2430
fi
2531

0 commit comments

Comments
 (0)