@@ -48,10 +48,10 @@ jobs:
4848 - name : Start Azure Cosmos DB Emulator using direct executable
4949 run : |
5050 Write-Host "Starting Cosmos DB Emulator using direct executable approach..."
51-
51+
5252 # Define emulator path
5353 $emulatorPath = "C:\Program Files\Azure Cosmos DB Emulator\CosmosDB.Emulator.exe"
54-
54+
5555 # Start emulator process directly with optimized settings
5656 Write-Host "Starting emulator process..."
5757 $processArgs = @(
@@ -61,34 +61,44 @@ jobs:
6161 "/PartitionCount=25"
6262 "/Consistency=Session"
6363 )
64-
64+
6565 $process = Start-Process -FilePath $emulatorPath -ArgumentList $processArgs -PassThru -WindowStyle Hidden
6666 Write-Host "Emulator process started with PID: $($process.Id)"
67-
67+
6868 # Wait for emulator to become responsive
6969 Write-Host "Waiting for emulator to become ready..."
7070 $maxWaitMinutes = 15
7171 $checkIntervalSeconds = 15
7272 $maxAttempts = [math]::Floor(($maxWaitMinutes * 60) / $checkIntervalSeconds)
7373 $attempt = 0
7474 $emulatorReady = $false
75-
75+
7676 while ($attempt -lt $maxAttempts -and -not $emulatorReady) {
7777 $attempt++
7878 $elapsedMinutes = [math]::Round(($attempt * $checkIntervalSeconds) / 60, 1)
7979 Write-Host "Checking emulator readiness (attempt $attempt/$maxAttempts, $elapsedMinutes min elapsed)..."
80-
80+
8181 try {
8282 # Check if the emulator endpoint is responding
83+ # A 401 Unauthorized response actually means the service is up and running!
8384 $response = Invoke-WebRequest -Uri "https://127.0.0.1:8081/" -UseBasicParsing -TimeoutSec 10 -SkipCertificateCheck
8485 if ($response.StatusCode -eq 200) {
8586 Write-Host "? Emulator is responding on HTTPS endpoint!"
8687 $emulatorReady = $true
8788 }
8889 } catch {
89- Write-Host "Emulator not ready yet (HTTPS check failed): $($_.Exception.Message)"
90+ # Check if we got a 401 Unauthorized - this actually means the service is ready!
91+ if ($_.Exception.Response.StatusCode -eq 401) {
92+ Write-Host "? Emulator is responding with 401 Unauthorized - service is ready!"
93+ $emulatorReady = $true
94+ } elseif ($_.Exception.Message -like "*401*" -or $_.Exception.Message -like "*Unauthorized*") {
95+ Write-Host "? Emulator is responding with authentication error - service is ready!"
96+ $emulatorReady = $true
97+ } else {
98+ Write-Host "Emulator not ready yet (HTTPS check failed): $($_.Exception.Message)"
99+ }
90100 }
91-
101+
92102 if (-not $emulatorReady) {
93103 # Also try to check if the process is still running
94104 try {
@@ -98,15 +108,15 @@ jobs:
98108 Write-Warning "Emulator process appears to have crashed!"
99109 break
100110 }
101-
111+
102112 Write-Host "Waiting $checkIntervalSeconds seconds before next check..."
103113 Start-Sleep -Seconds $checkIntervalSeconds
104114 }
105115 }
106-
116+
107117 if (-not $emulatorReady) {
108118 Write-Error "Cosmos DB Emulator failed to become ready within $maxWaitMinutes minutes"
109-
119+
110120 # Try to get some diagnostic information
111121 try {
112122 Write-Host "Checking for any emulator processes..."
@@ -116,33 +126,37 @@ jobs:
116126 } catch {
117127 Write-Host "Could not enumerate emulator processes"
118128 }
119-
129+
120130 exit 1
121131 }
122-
132+
123133 Write-Host "? Cosmos DB Emulator is ready and responding!"
124134 shell : pwsh
125135
126136 - name : Verify Cosmos DB Emulator Connection
127137 run : |
128138 Write-Host "Final verification of Cosmos DB Emulator..."
129-
130- # Test HTTPS endpoint
139+
140+ # Test HTTPS endpoint - 401 is expected and means the service is working
131141 try {
132142 $response = Invoke-WebRequest -Uri "https://127.0.0.1:8081/" -UseBasicParsing -SkipCertificateCheck -TimeoutSec 30
133143 Write-Host "? HTTPS endpoint accessible (Status: $($response.StatusCode))"
134144 } catch {
135- Write-Warning "HTTPS endpoint test failed: $($_.Exception.Message)"
145+ if ($_.Exception.Response.StatusCode -eq 401 -or $_.Exception.Message -like "*401*" -or $_.Exception.Message -like "*Unauthorized*") {
146+ Write-Host "? HTTPS endpoint accessible (Status: 401 Unauthorized - this is expected and correct)"
147+ } else {
148+ Write-Warning "HTTPS endpoint test failed: $($_.Exception.Message)"
149+ }
136150 }
137-
151+
138152 # Test the data explorer endpoint
139153 try {
140154 $response = Invoke-WebRequest -Uri "https://127.0.0.1:8081/_explorer/emulator.js" -UseBasicParsing -SkipCertificateCheck -TimeoutSec 30
141155 Write-Host "? Data Explorer endpoint accessible (Status: $($response.StatusCode))"
142156 } catch {
143157 Write-Warning "Data Explorer endpoint test failed: $($_.Exception.Message)"
144158 }
145-
159+
146160 # Display emulator info
147161 Write-Host "Emulator should be accessible at: https://127.0.0.1:8081"
148162 Write-Host "Primary Key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
0 commit comments