Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions test/tools/Modules/WebListener/WebListener.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can dotnet run fail here? Should we check a return code or the job return it automatically? Do we get this in $initStatus - if so we should change logic below for ending loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. dotnet run can fail here if somehow the SDK or source code is corrupt. We would see that in the output section of the new throw message. In fact, we should already see that in the current code before this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any benefit in changing the current logic. the timeout is 15 seconds. Failing early shaves off maybe a few seconds but adds complexity that could result in false fails or false successes. I say we leave it alone.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, my understanding is that if we don't get $initCompleteMessage we in any case get timeout error and a native error code which led to the lack of $initCompleteMessage.

I suggest checking this out. Could you please push a temporary commit to emulate an error in WebListener startup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iSazonov No. we were seeing no output at all when this happens which was indicating that dotent was either not running at all or was running and hung without any output. Even when it fails there is stdout output so we should have seen at least something. instead, we were simply timing out.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
I don't see our message "'WebListener did not start before the timeout was reached ..." in logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea.. erm.. -Force is not present on Stop-Job so that syntax error was popping up instead as it was hit first, so the throw message never made it through. I have corrected and repushed. I also had to change the temporary throw WebListener.. it wasn't compiling due to the unreachable code...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://ci.appveyor.com/project/PowerShell/powershell/build/v6.1.0-preview.7742#L2508

Describing Invoke-WebRequest tests
 [-] Error occurred in Describe block 16.43s
   WebListener did not start before the timeout was reached.
   Errors:
   NotSpecified: (:String) [], RemoteException
   Unhandled Exception: System.ApplicationException: Bad things happened.
      at mvc.Program.Main(String[] args) in C:\projects\powershell\test\tools\WebListener\Program.cs:line 23
   
   Output:
   appDLL: WebListener.dll
   serverPfxPath: C:\projects\powershell\test\tools\Modules\WebListener\ServerCert.pfx
   serverPfxPassword: password
   HttpPort: 8083
   Https: 8084
   Tls11Port: 8085
   TlsPort: 8086
   
   Verbose:
   
   At C:\projects\powershell\test\tools\Modules\WebListener\WebListener.psm1:107 char:13

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #6020 to track the issue where one of the describe blocks is missing Start-WebListener

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

}
$Script:WebListener = [WebListener]@{
Expand All @@ -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
}
Expand Down