-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdistribute_tests.sh
More file actions
41 lines (35 loc) · 2.1 KB
/
distribute_tests.sh
File metadata and controls
41 lines (35 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
#===============================================================================
#
# FILE: distribute_tests.sh
#
# USAGE: ./distribute_tests.sh
#
# DESCRIPTION: This script slices tests files across multiple agents for faster execution.
# We search for specific type of file structure (in this example test*), and slice them according to agent number
# 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
# We use JUnit test results to publish the test reports.
#
#===============================================================================
shopt -s globstar nullglob
tests=( "0"*/**/*"spec.js" ) ## search folders starting with 0 and contains test pattern *spec.js
IFS=$'\n' tests=($(sort <<<"${tests[*]}"))
unset IFS
totalAgents=$SYSTEM_TOTALJOBSINPHASE # standard VSTS variables available using parallel execution; total number of parallel jobs running
agentNumber=$SYSTEM_JOBPOSITIONINPHASE # current job position
testCount=${#tests[@]}
if [ $totalAgents -eq 0 ]; then totalAgents=1; fi # below conditions are used if parallel pipeline is not used. i.e. pipeline is running with single agent (no parallel configuration)
if [ -z "$agentNumber" ]; then agentNumber=1; fi
echo "Total agents: $totalAgents"
echo "Agent number: $agentNumber"
echo "Total test files: $testCount"
mkdir ./junitReports # create temporary directory to copy all test reports for publishing them
# slice test files to make sure each agent gets unique test file to execute
for (( i=$agentNumber; i<=$testCount; ))
do
file=${tests[$i-1]}
echo "Executing" "$(printf "./$file")"
./node_modules/.bin/mocha "$(printf "./$file")" --reporter mocha-multi-reporters --reporter-options configFile=config.json # essentially we are running mocha test1spec.js, mocha test3spec.js and so on
mv ./testresults/test-results.xml "$(printf "./junitReports/test-results$i.xml")" # copy test reports to publish them after the test execution is completed
i=$(($i+$totalAgents))
done