Skip to content

Commit

Permalink
Add Cosmos emulator brute force script & reenabling tests (#1570)
Browse files Browse the repository at this point in the history
  • Loading branch information
liliankasem authored and kshyju committed Jun 5, 2023
1 parent 109ff08 commit 5899543
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
9 changes: 4 additions & 5 deletions src/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ jobs:
buildConfiguration: 'Release'

steps:
- pwsh: . "tools/start-emulators.ps1" -NoWait -SkipCosmosDBEmulator
displayName: "Start emulators (-NoWait)"
- pwsh: . "tools/start-emulators.ps1"
displayName: "Start emulators"

- template: ../build/install-dotnet.yml

- task: DotNetCoreCLI@2
displayName: 'Build projects'
inputs:
Expand All @@ -63,8 +63,7 @@ jobs:
}
./setup-e2e-tests.ps1 -FunctionsRuntimeVersion $env:FUNCTIONSRUNTIMEVERSION `
-UseCoreToolsBuildFromIntegrationTests:$useIntegrationTestingCoreTools `
-SkipBuildOnPack `
-SkipCosmosDBEmulator
-SkipBuildOnPack
displayName: "Setup E2E tests"
- task: DotNetCoreCLI@2
Expand Down
4 changes: 2 additions & 2 deletions test/E2ETests/E2ETests/CosmosDBEndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public CosmosDBEndToEndTests(FunctionAppFixture fixture, ITestOutputHelper testO
_disposeLog = _fixture.TestLogs.UseTestLogger(testOutput);
}

[Fact(Skip = "Need to debug why Cosmos emulator does not always start.")]
[Fact]
public async Task CosmosDBTriggerAndOutput_Succeeds()
{
string expectedDocId = Guid.NewGuid().ToString();
try
{
//Trigger
//Trigger
await CosmosDBHelpers.CreateDocument(expectedDocId);

//Read
Expand Down
49 changes: 40 additions & 9 deletions tools/start-emulators.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Write-Host "Skip Storage Emulator: $SkipStorageEmulator"

if (!$SkipCosmosDBEmulator)
{
Add-MpPreference -ExclusionPath "$env:ProgramFiles\Azure Cosmos DB Emulator"
Import-Module "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"
}

Expand Down Expand Up @@ -58,17 +59,17 @@ if (!$SkipCosmosDBEmulator)
Write-Host "CosmosDB emulator status: $cosmosStatus"

if ($cosmosStatus -eq "StartPending")
{
{
$startedCosmos = $true
}
elseif ($cosmosStatus -ne "Running")
{
Write-Host "CosmosDB emulator is not running. Starting emulator."
Start-CosmosDbEmulator -NoWait -NoUI
Start-Process "$env:ProgramFiles\Azure Cosmos DB Emulator\CosmosDB.Emulator.exe" "/NoExplorer /NoUI /DisableRateLimiting /PartitionCount=50 /Consistency=Strong /EnablePreview /EnableSqlComputeEndpoint" -Verb RunAs
$startedCosmos = $true
}
else
{
{
Write-Host "CosmosDB emulator is already running."
}
}
Expand All @@ -79,7 +80,7 @@ if (!$SkipStorageEmulator)
Write-Host ""
Write-Host "---Starting Storage emulator---"
$storageEmulatorRunning = IsStorageEmulatorRunning

if ($storageEmulatorRunning -eq $false)
{
if ($IsWindows)
Expand All @@ -102,7 +103,7 @@ if (!$SkipStorageEmulator)
}

Write-Host "------"
Write-Host
Write-Host
}

if ($NoWait -eq $true)
Expand All @@ -123,9 +124,39 @@ if (!$SkipCosmosDBEmulator -and $startedCosmos -eq $true)
if ($waitSuccess -ne $true)
{
Write-Host "CosmosDB emulator not yet running after waiting 60 seconds. Restarting."
Stop-CosmosDbEmulator
Write-Host "Restarting CosmosDB emulator"
Start-CosmosDbEmulator -NoUI
Write-Host "Shutting down and restarting"
Start-Process "$env:ProgramFiles\Azure Cosmos DB Emulator\CosmosDB.Emulator.exe" "/Shutdown" -Verb RunAs
sleep 30;

for ($j=0; $j -lt 3; $j++) {
Write-Host "Attempt $j"
Start-Process "$env:ProgramFiles\Azure Cosmos DB Emulator\CosmosDB.Emulator.exe" "/NoExplorer /NoUI /DisableRateLimiting /PartitionCount=50 /Consistency=Strong /EnablePreview /EnableSqlComputeEndpoint" -Verb RunAs

for ($i=0; $i -lt 5; $i++) {
$status = Get-CosmosDbEmulatorStatus
Write-Host "Cosmos DB Emulator Status: $status"

if ($status -ne "Running") {
sleep 30;
}
else {
break;
}
}

if ($status -ne "Running") {
Write-Host "Shutting down and restarting"
Start-Process "$env:ProgramFiles\Azure Cosmos DB Emulator\CosmosDB.Emulator.exe" "/Shutdown" -Verb RunAs
sleep 30;
}
else {
break;
}
}

if ($status -ne "Running") {
Write-Error "Emulator failed to start"
}
}

Write-Host "------"
Expand All @@ -137,7 +168,7 @@ if (!$SkipStorageEmulator -and $startedStorage -eq $true)
Write-Host "---Waiting for Storage emulator to be running---"
$storageEmulatorRunning = IsStorageEmulatorRunning
while ($storageEmulatorRunning -eq $false)
{
{
Write-Host "Storage emulator not ready."
Start-Sleep -Seconds 5
$storageEmulatorRunning = IsStorageEmulatorRunning
Expand Down

0 comments on commit 5899543

Please sign in to comment.