forked from dotnet/orleans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parallel-Tests.ps1
99 lines (78 loc) · 2.54 KB
/
Parallel-Tests.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
param(
[string[]] $directories,
[string] $testFilter = $null)
. .\common.ps1
Install-Dotnet
$maxDegreeOfParallelism = [math]::min($env:NUMBER_OF_PROCESSORS, 4)
Write-Host "Max Job Parallelism = $maxDegreeOfParallelism"
$failed = $false
if(
[Console]::InputEncoding -is [Text.UTF8Encoding] -and
[Console]::InputEncoding.GetPreamble().Length -ne 0
) {
Write-Host Setting [Console]::InputEncoding
[Console]::InputEncoding = New-Object Text.UTF8Encoding $false
}
else
{
Write-Host Not changing [Console]::InputEncoding
}
if ([string]::IsNullOrWhiteSpace($testFilter)) {
$testFilter = $env:TEST_FILTERS;
}
if ([string]::IsNullOrWhiteSpace($testFilter)) {
$testFilter = "Category=BVT|Category=SlowBVT";
}
Write-Host "Test filters: `"$testFilter`"";
function Receive-CompletedJobs {
$succeeded = $true
foreach($job in (Get-Job | Where-Object { $_.State -ne 'Running' }))
{
Receive-Job $job -AutoRemoveJob -Wait | Write-Host
if ($job.State -eq 'Failed') {
$succeeded = $false
Write-Host -ForegroundColor Red 'Failed: ' $job.Name '('$job.State')'
}
Write-Host ''
}
return $succeeded
}
$ExecuteCmd =
{
param([string] $args1, [string] $path)
Set-Location -Path "$path"
$cmdline = "& dotnet " + $args1
Invoke-Expression $cmdline;
$cmdExitCode = $LASTEXITCODE;
if ($cmdExitCode -ne 0)
{
Throw "Error when running tests. Command: `"$cmdline`". Exit Code: $cmdExitCode"
}
else
{
Write-Host "Tests completed. Command: `"$cmdline`""
}
}
foreach ($d in $directories)
{
$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
if ($running.Count -ge $maxDegreeOfParallelism) {
$running | Wait-Job -Any | Out-Null
}
if (-not (Receive-CompletedJobs)) { $failed = $true }
if (-not $testFilter.StartsWith('"')) { $testFilter = "`"$testFilter"; }
if (-not $testFilter.EndsWith('"')) { $testFilter = "$testFilter`""; }
$jobName = $([System.IO.Path]::GetFileName($d))
$cmdLine = 'test --blame-hang-timeout 10m --no-build --configuration "' + $env:BuildConfiguration + '" --filter ' + $testFilter + ' --logger "trx" -- -parallel none -noshadow'
Write-Host $jobName dotnet $cmdLine
Start-Job $ExecuteCmd -ArgumentList @($cmdLine, "$d") -Name $jobName | Out-Null
Write-Host ''
}
# Wait for all jobs to complete and results ready to be received
Wait-Job * | Out-Null
if (-not (Receive-CompletedJobs)) { $failed = $true }
if ($failed)
{
Write-Host 'Test run failed'
Exit 1
}