-
Notifications
You must be signed in to change notification settings - Fork 0
/
DistributeTests.ps1
76 lines (68 loc) · 3.07 KB
/
DistributeTests.ps1
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<#
.SYNOPSIS
Distribute the tests in VSTS pipeline across multiple agents
.DESCRIPTION
This script divides test files across multiple agents for running on Azure DevOps.
It is adapted from the script in this repository:
https://github.com/PBoraMSFT/ParallelTestingSample-Python/blob/master/DistributeTests.ps1
The distribution is basically identical to the way we do it in .travis.yaml
#>
$tests = Get-ChildItem rsmcode\tests\ -Filter "test*.py" # search for test files with specific pattern.
$totalAgents = [int]$Env:SYSTEM_TOTALJOBSINPHASE # standard VSTS variables available using parallel execution; total number of parallel jobs running
$agentNumber = [int]$Env:SYSTEM_JOBPOSITIONINPHASE # current job position
$testCount = $tests.Count
# below conditions are used if parallel pipeline is not used. i.e. pipeline is running with single agent (no parallel configuration)
if ($totalAgents -eq 0) {
$totalAgents = 1
}
if (!$agentNumber -or $agentNumber -eq 0) {
$agentNumber = 1
}
Write-Host "Total agents: $totalAgents"
Write-Host "Agent number: $agentNumber"
Write-Host "Total tests: $testCount"
$testsToRun= @()
if ($agentNumber -eq 1) {
$testsToRun = $testsToRun + "test_experiment_rsmtool_1"
}
elseif ($agentNumber -eq 2) {
$testsToRun = $testsToRun + "test_comparer"
$testsToRun = $testsToRun + "test_configuration_parser"
$testsToRun = $testsToRun + "test_experiment_rsmtool_2"
$testsToRun = $testsToRun + "test_container"
}
elseif ($agentNumber -eq 3) {
$testsToRun = $testsToRun + "test_analyzer"
$testsToRun = $testsToRun + "test_experiment_rsmeval"
$testsToRun = $testsToRun + "test_fairness_utils"
$testsToRun = $testsToRun + "test_utils_prmse"
$testsToRun = $testsToRun + "test_test_utils"
$testsToRun = $testsToRun + "test_cli"
}
elseif ($agentNumber -eq 4) {
$testsToRun = $testsToRun + "test_experiment_rsmcompare"
$testsToRun = $testsToRun + "test_experiment_rsmsummarize"
$testsToRun = $testsToRun + "test_modeler"
$testsToRun = $testsToRun + "test_preprocessor"
$testsToRun = $testsToRun + "test_writer"
$testsToRun = $testsToRun + "test_experiment_rsmtool_3"
}
elseif ($agentNumber -eq 5) {
$testsToRun = $testsToRun + "test_experiment_rsmpredict"
$testsToRun = $testsToRun + "test_reader"
$testsToRun = $testsToRun + "test_reporter"
$testsToRun = $testsToRun + "test_transformer"
$testsToRun = $testsToRun + "test_utils"
$testsToRun = $testsToRun + "test_experiment_rsmtool_4"
}
elseif ($agentNumber -eq 6) {
$testsToRun = $testsToRun + "test_experiment_rsmxval"
$testsToRun = $testsToRun + "test_experiment_rsmexplain"
$testsToRun = $testsToRun + "test_explanation_utils"
$testsToRun = $testsToRun + "test_wandb"
}
# join all test files seperated by space. pytest runs multiple test files in following format pytest test1.py test2.py test3.py
$testFiles = $testsToRun -Join " "
Write-Host "Test files $testFiles"
# write these files into variable so that we can run them using pytest in subsequent task.
Write-Host "##vso[task.setvariable variable=pytestfiles;]$testFiles"