From 6b20360f7ce9efa0c2b55b8871c213105c2d5268 Mon Sep 17 00:00:00 2001 From: Ishaat Chowdhury Date: Mon, 18 Mar 2024 14:15:00 -0700 Subject: [PATCH] Add powershell script to check emulator startup --- scripts/Check-EmulatorStartup.ps1 | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 scripts/Check-EmulatorStartup.ps1 diff --git a/scripts/Check-EmulatorStartup.ps1 b/scripts/Check-EmulatorStartup.ps1 new file mode 100644 index 0000000..eeb009c --- /dev/null +++ b/scripts/Check-EmulatorStartup.ps1 @@ -0,0 +1,38 @@ +[CmdletBinding()] +param +( + [string] + $IpAddress = "localhost", + + [System.TimeSpan] + $Timeout = $(New-TimeSpan -Minutes 2), + + [int] + $Port = 8081 +) + +$ErrorActionPreference = "Stop" + +$StartTime = $(Get-Date) +$EndTime = $StartTime + $Timeout +$StatusCode = -1 +do +{ + $StatusCode = try + { + $(Invoke-WebRequest -Uri "https://$($IpAddress):$($Port)/_explorer/emulator.pem" -UseBasicParsing -TimeoutSec 5 -ErrorAction Stop).BaseResponse.StatusCode + } catch [System.Net.WebException] { + $_.Exception.Response.StatusCode + } + + if ($StatusCode -eq 200) + { + Write-Host "Emulator startup completed" + return + } + + Start-Sleep -Seconds 2 +} +while ($(Get-Date) -lt $EndTime) + +throw "Emulator not reachable within timeout $Timeout! Last retrieved status code: $StatusCode." \ No newline at end of file