forked from dotnet/interactive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-retry-runner.ps1
85 lines (77 loc) · 3.34 KB
/
test-retry-runner.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
[CmdletBinding(PositionalBinding = $false)]
param (
[int]$retryCount = 5,
[string]$buildConfig = "Debug"
)
Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"
if ($IsWindows) {
$projectsToSkip = @(
"Microsoft.DotNet.Interactive.CSharpProject.Tests"
)
}
else
{
$projectsToSkip = @(
"Microsoft.DotNet.Interactive.NetFramework.Tests",
"Microsoft.DotNet.Interactive.CSharpProject.Tests"
"Microsoft.DotNet.Interactive.NamedPipeConnector.Tests",
"Microsoft.DotNet.Interactive.VisualStudio.Tests"
)
}
function ExecuteTestDirectory([string]$testDirectory, [string]$extraArgs = "") {
$testCommand = "dotnet test $testDirectory/ $extraArgs -l trx --no-restore --no-build --blame-hang-timeout 15m --blame-hang-dump-type full --blame-crash -c $buildConfig --results-directory $repoRoot/artifacts/TestResults/$buildConfig"
Write-Host "Executing $testCommand"
Invoke-Expression $testCommand
}
try {
$repoRoot = Resolve-Path $PSScriptRoot
$flakyTestAssemblyDirectories = @(
"Microsoft.DotNet.Interactive.Tests",
"Microsoft.DotNet.Interactive.App.Tests",
"Microsoft.DotNet.Interactive.Browser.Tests",
"Microsoft.DotNet.Interactive.Jupyter.Tests"
)
$normalTestAssemblyDirectories = Get-ChildItem -Path "$repoRoot/src" -Directory -Filter *.Tests -Recurse | Where-Object { !$flakyTestAssemblyDirectories.contains($_.Name)}
foreach ($testAssemblyDirectory in $normalTestAssemblyDirectories) {
$projectName = $testAssemblyDirectory.Name
if($projectsToSkip.contains($projectName)){
Write-Host "Skipping test project $projectName"
continue
}
for ($i = 1; $i -le $retryCount; $i++) {
Write-Host "Testing project $projectName, attempt $i"
ExecuteTestDirectory -testDirectory $testAssemblyDirectory
if ($LASTEXITCODE -eq 0) {
break
}
}
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
}
foreach ($flakyTestAssemblyDirectory in $flakyTestAssemblyDirectories){
$testNamePattern = " ([^(]+)" # skip 4 spaces then get everything that's not a left paren because test names start with 4 spaces and [Theory] tests have a parenthesized argument list
$testNames = dotnet test "$repoRoot/src/$flakyTestAssemblyDirectory/" --no-restore --no-build --configuration $buildConfig --list-tests | Select-String -Pattern $testNamePattern | ForEach-Object { $_.Matches[0].Groups[1].Value }
$testClasses = $testNames | ForEach-Object { $_.Substring(0, $_.LastIndexOf([char]".")) } # trim off the test name, just get the class
$distinctTestClasses = $testClasses | Get-Unique
foreach ($testClass in $distinctTestClasses) {
for ($i = 1; $i -le $retryCount; $i++) {
Write-Host "Testing class $testClass, attempt $i"
ExecuteTestDirectory -testDirectory "$repoRoot/src/$flakyTestAssemblyDirectory" -extraArgs "--filter FullyQualifiedName~$testClass"
if ($LASTEXITCODE -eq 0) {
break
}
}
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
}
}
}
catch {
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
exit 1
}