9090 'NUnit.DefaultTestNamePattern={C}:{m}{a}'
9191 'RunConfiguration.TargetPlatform=${{inputs.architecture}}'
9292 )
93+ $testTimeout = if ("${{inputs.runtime-type}}" -eq "mono") {
94+ [TimeSpan]::FromMinutes(3)
95+ } else {
96+ [TimeSpan]::FromMinutes(5)
97+ }
98+
99+ function Test-TrxSucceeded($trxPath) {
100+ if (-not (Test-Path $trxPath)) {
101+ return $false
102+ }
103+ try {
104+ [xml]$trx = Get-Content $trxPath
105+ $resultSummary = $trx.SelectSingleNode('//*[local-name()="ResultSummary"]')
106+ if ($null -eq $resultSummary -or $resultSummary.GetAttribute('outcome') -ne 'Completed') {
107+ return $false
108+ }
109+ $counters = $resultSummary.SelectSingleNode('*[local-name()="Counters"]')
110+ if ($null -eq $counters) {
111+ return $false
112+ }
113+ return [int]$counters.GetAttribute('failed') -eq 0 `
114+ -and [int]$counters.GetAttribute('error') -eq 0 `
115+ -and [int]$counters.GetAttribute('timeout') -eq 0 `
116+ -and [int]$counters.GetAttribute('aborted') -eq 0
117+ } catch {
118+ Write-Warning "Unable to read test result file '$trxPath': $_"
119+ return $false
120+ }
121+ }
122+
123+ function Invoke-VSTest($fileName, [string[]]$arguments, $trxPath, $targetFramework) {
124+ $startInfo = [System.Diagnostics.ProcessStartInfo]::new()
125+ $startInfo.FileName = $fileName
126+ $startInfo.UseShellExecute = $false
127+ foreach ($argument in $arguments) {
128+ [void]$startInfo.ArgumentList.Add($argument)
129+ }
130+
131+ $process = [System.Diagnostics.Process]::Start($startInfo)
132+ if (-not $process.WaitForExit([int]$testTimeout.TotalMilliseconds)) {
133+ if ("${{inputs.runtime-type}}" -eq "mono" -and (Test-TrxSucceeded $trxPath)) {
134+ Write-Warning "Mono VSTest did not exit after successful $targetFramework test run; terminating the stuck process and continuing."
135+ try {
136+ $process.Kill($true)
137+ } catch {
138+ $process.Kill()
139+ }
140+ $process.WaitForExit()
141+ return
142+ }
143+
144+ try {
145+ $process.Kill($true)
146+ } catch {
147+ $process.Kill()
148+ }
149+ $process.WaitForExit()
150+ throw "Timed out after $($testTimeout.TotalMinutes) minutes waiting for $targetFramework tests."
151+ }
152+
153+ if ($process.ExitCode -ne 0) {
154+ exit $process.ExitCode
155+ }
156+ }
93157
94158 foreach ($target_framework in ConvertFrom-Json "${{steps.test-args.outputs.target_frameworks}}") {
95159 $trxFileName = "${{inputs.os}}-${{inputs.architecture}}-${{inputs.runtime-type}}-${{inputs.build_configuration}}-$target_framework.trx"
160+ $trxPath = Join-Path "TestResults" $trxFileName
96161 $testCommand = $vstest
97162 $testArguments = @(
98163 " HarmonyTests/bin/${{inputs.build_configuration}}/$target_framework/HarmonyTests.dll"
@@ -109,10 +174,7 @@ runs:
109174 $testCommand = $mono
110175 $testArguments = @($vstest) + $testArguments
111176 }
112- & $testCommand @testArguments
113- if ($LASTEXITCODE -ne 0) {
114- exit $LASTEXITCODE
115- }
177+ Invoke-VSTest -fileName $testCommand -arguments $testArguments -trxPath $trxPath -targetFramework $target_framework
116178 }
117179 shell : pwsh
118180
0 commit comments