forked from dotnet/orleans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parallel-Tests.ps1
66 lines (53 loc) · 1.7 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
param(
[string[]] $directories,
[string] $testFilter,
[string] $outDir,
[string] $dotnet)
$maxDegreeOfParallelism = 4
$failed = $false
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] $dotnet1, [string] $args1, [string] $path)
Set-Location -Path $path
$cmdline = "& `"" + $dotnet1 + "`" " + $args1
Invoke-Expression $cmdline
if ($LASTEXITCODE -ne 0)
{
Throw "Error when running tests"
}
}
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 }
$xmlName = 'xUnit-Results-' + [System.IO.Path]::GetFileName($d) + '.xml'
$outXml = $(Join-Path $outDir $xmlName)
$cmdLine = 'xunit ' + $testFilter + ' -xml ' + $outXml + ' -parallel none -noshadow -nobuild -configuration ' + $env:BuildConfiguration
Write-Host $dotnet $cmdLine
Start-Job $ExecuteCmd -ArgumentList @($dotnet, $cmdLine, $d) -Name $([System.IO.Path]::GetFileName($d)) | 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
}