@@ -88,6 +88,9 @@ function Invoke-PhpTests {
8888 Set-SnmpTestEnvironment - TestsDirectoryPath " $buildDirectory \$testsDirectory "
8989 }
9090
91+ $testResultFile = " $buildDirectory \test-$Arch -$Ts -$Opcache -$TestType .xml"
92+ $testLogFile = " $buildDirectory \test-$Arch -$Ts -$Opcache -$TestType .log"
93+
9194 $params = @ (
9295 " -d" , " open_basedir=" ,
9396 " -d" , " output_buffering=0" ,
@@ -104,16 +107,64 @@ function Invoke-PhpTests {
104107 " -r" , " $TestType -tests-to-run.txt"
105108 )
106109
110+ $workersParam = " "
107111 if ($settings.workers -ne " " ) {
108- $params += $settings.workers
112+ $workersParam = $settings.workers
113+ $params += $workersParam
109114 }
110115
111- & $buildDirectory \phpbin\php.exe @params
116+ $invokeTests = {
117+ param (
118+ [string []] $RunnerParams ,
119+ [string ] $LogFilePath
120+ )
121+ if (Test-Path $LogFilePath ) {
122+ Remove-Item $LogFilePath - Force
123+ }
124+
125+ & $buildDirectory \phpbin\php.exe @RunnerParams 2>&1 | Tee-Object - FilePath $LogFilePath | Out-Host
126+ return [int ]$LASTEXITCODE
127+ }
112128
113- Copy-Item " $buildDirectory \test-$Arch -$Ts -$Opcache -$TestType .xml" $currentDirectory
129+ $isWorkerCrash = {
130+ param (
131+ [string ] $LogFilePath
132+ )
133+ return (Test-Path $LogFilePath ) -and (Select-String - Path $LogFilePath - Pattern " ERROR:\s+Worker \d+ died unexpectedly" - Quiet)
134+ }
135+
136+ $exitCode = & $invokeTests - RunnerParams $params - LogFilePath $testLogFile
137+
138+ if ($exitCode -ne 0 -and $workersParam -ne " " ) {
139+ $baseParams = @ ($params | Where-Object { $_ -ne $workersParam })
140+ $workerDied = & $isWorkerCrash - LogFilePath $testLogFile
141+ if ($workerDied ) {
142+ Write-Warning " Detected a run-tests worker crash. Retrying once with -j2."
143+ $retryWithTwoWorkersParams = @ ($baseParams + " -j2" )
144+ $exitCode = & $invokeTests - RunnerParams $retryWithTwoWorkersParams - LogFilePath $testLogFile
145+
146+ if ($exitCode -ne 0 ) {
147+ $workerDied = & $isWorkerCrash - LogFilePath $testLogFile
148+ if ($workerDied ) {
149+ Write-Warning " Detected another worker crash with -j2. Retrying once without parallel workers."
150+ $exitCode = & $invokeTests - RunnerParams $baseParams - LogFilePath $testLogFile
151+ }
152+ }
153+ }
154+ }
155+
156+ if (Test-Path $testResultFile ) {
157+ Copy-Item $testResultFile $currentDirectory - Force
158+ } else {
159+ Write-Warning " Test results file was not generated: $testResultFile "
160+ }
114161
115162 Set-Location " $currentDirectory "
163+
164+ if ($exitCode -ne 0 ) {
165+ Write-Warning " PHP tests exited with code $exitCode ."
166+ }
116167 }
117168 end {
118169 }
119- }
170+ }
0 commit comments