diff --git a/eng/scripts/Compare-CurrentToCodegeneration.ps1 b/eng/scripts/Compare-CurrentToCodegeneration.ps1 index b4893bb8745f..683abf7eb841 100644 --- a/eng/scripts/Compare-CurrentToCodegeneration.ps1 +++ b/eng/scripts/Compare-CurrentToCodegeneration.ps1 @@ -208,7 +208,14 @@ $generateScript = { } # Timeout is set to 60 seconds per script. -$timeout = 60 * $generationInformations.Count +$scriptTimeoutInSeconds = 60 +$timeout = $scriptTimeoutInSeconds * $generationInformations.Count +# Ensure a minimum timeout of 5 times the script timeout +# This is for scenarios where there are only a few scripts to run. Some script with large TypeSpec source can take a few minutes. +$minimumTimeout = 5 * $scriptTimeoutInSeconds +if ($timeout -lt $minimumTimeout) { + $timeout = $minimumTimeout +} $job = $generationInformations | ForEach-Object -Parallel $generateScript -ThrottleLimit $Parallelization -AsJob @@ -216,8 +223,14 @@ $job = $generationInformations | ForEach-Object -Parallel $generateScript -Throt $job | Wait-Job -Timeout $timeout | Out-Null $job | Receive-Job 2>$null | Out-Null +$jobTimeout = $job.State -eq 'Running' +$jobFailed = $job.State -eq 'Failed' +if ($jobTimeout) { + Write-Host "The aggregated generate job timed out after $timeout seconds." +} + # Clean up generated code, so that next step will not be affected. git reset --hard | Out-Null git clean -fd . | Out-Null -exit $job.State -eq 'Failed' +exit $jobFailed -or $jobTimeout