Test: Add Verbosity and more accurate timeout implementation for Start-WebListener (#6013)
- Add verbosity to the WebListener when it fails to assist in troubleshooting - Switch the WebListener initialization timeout to count cycles instead of using fixed dates to work around possible VM CI sleep/ issues.
This commit is contained in:
parent
1c5c7f5c3a
commit
47c4a0a74b
|
@ -60,12 +60,20 @@ function Start-WebListener
|
|||
$serverPfx = 'ServerCert.pfx'
|
||||
$serverPfxPassword = 'password'
|
||||
$initCompleteMessage = 'Now listening on'
|
||||
$sleepMilliseconds = 100
|
||||
|
||||
$serverPfxPath = Join-Path $MyInvocation.MyCommand.Module.ModuleBase $serverPfx
|
||||
$timeOut = (get-date).AddSeconds($initTimeoutSeconds)
|
||||
$Job = Start-Job {
|
||||
$path = Split-Path -parent (get-command WebListener).Path
|
||||
Push-Location $path
|
||||
$path = Split-Path -parent (get-command WebListener).Path -Verbose
|
||||
Push-Location $path -Verbose
|
||||
'appDLL: {0}' -f $using:appDll
|
||||
'serverPfxPath: {0}' -f $using:serverPfxPath
|
||||
'serverPfxPassword: {0}' -f $using:serverPfxPassword
|
||||
'HttpPort: {0}' -f $using:HttpPort
|
||||
'Https: {0}' -f $using:HttpsPort
|
||||
'Tls11Port: {0}' -f $using:Tls11Port
|
||||
'TlsPort: {0}' -f $using:TlsPort
|
||||
$env:ASPNETCORE_ENVIRONMENT = 'Development'
|
||||
dotnet $using:appDll $using:serverPfxPath $using:serverPfxPassword $using:HttpPort $using:HttpsPort $using:Tls11Port $using:TlsPort
|
||||
}
|
||||
$Script:WebListener = [WebListener]@{
|
||||
|
@ -75,20 +83,28 @@ function Start-WebListener
|
|||
TlsPort = $TlsPort
|
||||
Job = $Job
|
||||
}
|
||||
# Wait until the app is running or until the initTimeoutSeconds have been reached
|
||||
|
||||
# Count iterations of $sleepMilliseconds instead of using system time to work around possible CI VM sleep/delays
|
||||
$sleepCountRemaining = $initTimeoutSeconds * 1000 / $sleepMilliseconds
|
||||
do
|
||||
{
|
||||
Start-Sleep -Milliseconds 100
|
||||
Start-Sleep -Milliseconds $sleepMilliseconds
|
||||
$initStatus = $Job.ChildJobs[0].Output | Out-String
|
||||
$isRunning = $initStatus -match $initCompleteMessage
|
||||
$sleepCountRemaining--
|
||||
}
|
||||
while (-not $isRunning -and (get-date) -lt $timeOut)
|
||||
while (-not $isRunning -and $sleepCountRemaining -gt 0)
|
||||
|
||||
if (-not $isRunning)
|
||||
{
|
||||
$Job | Stop-Job -PassThru | Receive-Job
|
||||
$Job | Remove-Job
|
||||
throw 'WebListener did not start before the timeout was reached.'
|
||||
$jobErrors = $Job.ChildJobs[0].Error | Out-String
|
||||
$jobOutput = $Job.ChildJobs[0].Output | Out-String
|
||||
$jobVerbose = $Job.ChildJobs[0].Verbose | Out-String
|
||||
$Job | Stop-Job
|
||||
$Job | Remove-Job -Force
|
||||
$message = 'WebListener did not start before the timeout was reached.{0}Errors:{0}{1}{0}Output:{0}{2}{0}Verbose:{0}{3}' -f
|
||||
([System.Environment]::NewLine), $jobErrors, $jobOutput, $jobVerbose
|
||||
throw $message
|
||||
}
|
||||
return $Script:WebListener
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue