Skip to content

Commit 9bf7953

Browse files
committed
Address review comments
1 parent ff6eb3a commit 9bf7953

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

AzureDevOps/DistributeTests.ps1

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<#
22
.SYNOPSIS
3-
Distribute the tests in VSTS pipeline across multiple agents
3+
Distribute tests across multiple agents in VSTS pipeline
44
.DESCRIPTION
5-
This script slices tests files across multiple agents for faster execution.
6-
We search for specific type of file structure (in this example test*), and slice them according to agent number
7-
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
8-
For detalied slicing info: https://docs.microsoft.com/en-us/vsts/pipelines/test/parallel-testing-any-test-runner
5+
This script divides test files among multiple agents for faster execution. It searches for files matching a specific pattern (for example, `test*`) and assigns them based on the agent number.
6+
For example, if there are multiple files [test1..test10] and 2 agents:
7+
- Agent 1 runs tests from odd-numbered files.
8+
- Agent 2 runs tests from even-numbered files.
9+
For detailed slicing information, see https://docs.microsoft.com/en-us/vsts/pipelines/test/parallel-testing-any-test-runner
910
#>
1011

11-
$tests = Get-ChildItem .\tests\ -File # search for test files with specific pattern.
12-
$totalAgents = [int]$Env:SYSTEM_TOTALJOBSINPHASE # standard VSTS variables available using parallel execution; total number of parallel jobs running
13-
$agentNumber = [int]$Env:SYSTEM_JOBPOSITIONINPHASE # current job position
12+
$tests = Get-ChildItem .\tests\ -Filter *.m -File # Search for test files matching the specified pattern
13+
$totalAgents = [int]$Env:SYSTEM_TOTALJOBSINPHASE # Standard VSTS variable containing the number of parallel jobs
14+
$agentNumber = [int]$Env:SYSTEM_JOBPOSITIONINPHASE # Current job position
1415
$testCount = $tests.Count
1516

16-
# below conditions are used if parallel pipeline is not used. i.e. pipeline is running with single agent (no parallel configuration)
17+
# Handle cases where the pipeline runs without parallel configuration (single agent)
1718
if ($totalAgents -eq 0) {
1819
$totalAgents = 1
1920
}
@@ -27,18 +28,17 @@ Write-Host "Total tests: $testCount"
2728

2829
$testsToRun= @()
2930

30-
# slice test files to make sure each agent gets unique test file to execute
31+
# Slice test files so each agent gets a unique set of files to execute
3132
For ($i=$agentNumber; $i -le $testCount;) {
3233
$file = $tests[$i-1]
3334

3435
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
3536
$testsToRun += "$fileName/*"
36-
Write-Host "Added $file"
3737
$i = $i + $totalAgents
3838
}
3939

40-
# join all test files seperated by space.
40+
# Join all test files into a space-separated string
4141
$testFiles = $testsToRun -Join " "
42-
Write-Host "Test files $testFiles"
43-
# write these files into variable so that we can run them using pytest in subsequent task.
42+
Write-Host "Tests to run $testFiles"
43+
# Write files into a variable for execution in a subsequent task
4444
Write-Host "##vso[task.setvariable variable=MATLABTestFiles;]$testFiles"

AzureDevOps/DistributeTests.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,29 @@
55
#
66
# USAGE: ./distribute_tests.sh
77
#
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
8+
# DESCRIPTION: This script divides test files among multiple agents for faster execution. It searches for files matching a specific pattern (for example, `test*`) and assigns them based on the agent number.
9+
# For example, if there are multiple files [test1..test10] and 2 agents:
10+
# - Agent 1 runs tests from odd-numbered files.
11+
# - Agent 2 runs tests from even-numbered files.
12+
# For detailed slicing information, see https://docs.microsoft.com/en-us/vsts/pipelines/test/parallel-testing-any-test-runner
1113
#
1214
#===============================================================================
1315

1416
tests=()
17+
# Search for test files matching the specified pattern
1518
while IFS= read -r file; do
1619
tests+=("$file")
1720
done < <(find ./tests -type f -name "*.m" | sort)
1821

1922
# Use Azure DevOps variables
20-
totalAgents=${SYSTEM_TOTALJOBSINPHASE}
21-
agentNumber=${SYSTEM_JOBPOSITIONINPHASE}
23+
totalAgents=${SYSTEM_TOTALJOBSINPHASE} # Standard VSTS variable containing the number of parallel jobs
24+
agentNumber=${SYSTEM_JOBPOSITIONINPHASE} # Current job positioN
2225
testCount=${#tests[@]}
2326

27+
# Handle cases where the pipeline runs without parallel configuration (single agent)
2428
if [ $totalAgents -eq 0 ]; then
2529
totalAgents=1
2630
fi
27-
# below conditions are used if parallel pipeline is not used. i.e. pipeline is running with single agent (no parallel configuration)
2831
if [ -z $agentNumber ]; then
2932
agentNumber=1
3033
fi
@@ -35,18 +38,17 @@ echo "Total tests: $testCount"
3538

3639
testsToRun=()
3740

38-
# Slice test files so each agent gets unique files (1-based index)
41+
# Slice test files so each agent gets a unique set of files
3942
for (( i=agentNumber; i<=testCount; i+=totalAgents )); do
4043
file="${tests[i-1]}"
4144

4245
fileName=$(basename "$file" .m)
4346
testsToRun+=("${fileName}/*")
44-
echo "Added $fileName"
4547
done
4648

47-
# Join all test files separated by space
49+
# Join all test files into a space-separated string
4850
testFiles="${testsToRun[*]}"
49-
echo "Test files $testFiles"
51+
echo "Tests to run $testFiles"
5052

51-
# Set as Azure Pipelines variable
53+
# Write files into a variable for execution in a subsequent task
5254
echo "##vso[task.setvariable variable=MATLABTestFiles;]$testFiles"

0 commit comments

Comments
 (0)