forked from dotnet/orleans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParallel-Tests.ps1
66 lines (55 loc) · 1.89 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[]] $assemblies,
[string] $testFilter,
[string] $outDir)
$maxDegreeOfParallelism = 3
$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
}
# If there is multiple xunit packages installed, take the latest one
$xunitRunner = Get-ChildItem packages -Directory -Filter "xunit.runner.console.*" |
ForEach-Object { Get-ChildItem $_.FullName -Recurse -File -Filter "xunit.console.exe" } |
Sort-Object -Property VersionInfo |
Select-Object -Last 1
$ExecuteCmd =
{
param($cmd)
Invoke-Expression $cmd
if ($LASTEXITCODE -ne 0)
{
Throw "Error when running tests"
}
}
foreach ($a in $assemblies)
{
$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]::GetFileNameWithoutExtension($a) + '.xml'
$outXml = $(Join-Path $outDir $xmlName)
$cmdLine = $xunitRunner.FullName + ' ' + $a + ' ' + $testFilter + ' -xml ' + $outXml + ' -parallel none -noshadow -verbose'
Write-Host $cmdLine
Start-Job $ExecuteCmd -ArgumentList $cmdLine -Name $([System.IO.Path]::GetFileNameWithoutExtension($a)) | 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
}