-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add scripts to run Cosmos tests on a container #37110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AndriySvyryd
wants to merge
4
commits into
main
Choose a base branch
from
TestHelixCosmos
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+443
−17
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Starts the Azure Cosmos DB Emulator in a Windows Docker container and waits for it to be ready. | ||
| # Tests run on the host machine connecting to the emulator via https://localhost:8081. | ||
| # Usage: .\run-cosmos-container.ps1 | ||
| param() | ||
|
|
||
| $ErrorActionPreference = 'Stop' | ||
| $image = 'mcr.microsoft.com/cosmosdb/windows/azure-cosmos-emulator' | ||
| $containerName = 'cosmos-emulator' | ||
| $port = 8081 | ||
| $maxRetries = 90 | ||
| $retryDelaySec = 2 | ||
|
|
||
| Write-Host "Pulling image: $image" | ||
| docker pull $image | ||
| if ($LASTEXITCODE -ne 0) { throw "docker pull failed with exit code $LASTEXITCODE" } | ||
|
|
||
| Write-Host "Checking for existing container named $containerName..." | ||
| $existingContainerId = docker ps -a --filter "name=^${containerName}$" --format '{{.ID}}' | ||
| if ($LASTEXITCODE -ne 0) { throw "docker ps failed with exit code $LASTEXITCODE" } | ||
| if ($existingContainerId) { | ||
| Write-Host "Existing container '$containerName' found. Stopping and removing it..." | ||
| docker stop $containerName 2>$null | ||
| docker rm -f $containerName | ||
| if ($LASTEXITCODE -ne 0) { throw "docker rm failed with exit code $LASTEXITCODE" } | ||
| } | ||
|
|
||
| # -t is required because Start.ps1 sets [Console]::BufferWidth which needs a TTY handle. | ||
| Write-Host "Starting Cosmos DB Emulator container on port $port..." | ||
| docker run -d -t ` | ||
| --name $containerName ` | ||
| --publish "${port}:8081" ` | ||
| --memory 2G ` | ||
| $image | ||
| if ($LASTEXITCODE -ne 0) { throw "docker run failed with exit code $LASTEXITCODE" } | ||
AndriySvyryd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Write-Host "Waiting for emulator to be ready (up to $($maxRetries * $retryDelaySec)s)..." | ||
| $ready = $false | ||
| for ($i = 0; $i -lt $maxRetries; $i++) { | ||
| Start-Sleep -Seconds $retryDelaySec | ||
| # Any HTTP response (even 401) means the emulator is up and accepting connections. | ||
| $null = & curl.exe -k "https://localhost:${port}/" --silent --output NUL --max-time 5 | ||
| if ($LASTEXITCODE -eq 0) { | ||
| $ready = $true | ||
| } else { | ||
| Write-Host " Attempt $($i+1)/$maxRetries - not ready yet..." | ||
| } | ||
| if ($ready) { | ||
| Write-Host "Cosmos DB Emulator is ready on port $port." | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if (-not $ready) { | ||
| Write-Host "Emulator did not become ready. Container logs:" | ||
| docker logs $containerName | ||
| docker stop $containerName 2>$null | ||
| docker rm -f $containerName 2>$null | ||
| exit 1 | ||
| } | ||
|
|
||
| exit 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #!/usr/bin/env bash | ||
| # Starts the Azure Cosmos DB Linux (vNext) Emulator in a Docker container and waits for it to be ready. | ||
| # Tests run on the host machine connecting to the emulator via https://localhost:8081. | ||
| # The --protocol https flag is required because the .NET SDK does not support HTTP mode. | ||
| # Usage: ./run-cosmos-container.sh | ||
|
|
||
| set -e | ||
|
|
||
| image='mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview' | ||
| container_name='cosmos-emulator' | ||
| port=8081 | ||
| max_retries=30 | ||
| retry_delay=2 | ||
AndriySvyryd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| echo "Pulling image: $image" | ||
| docker pull "$image" | ||
|
|
||
| if docker ps -a --format '{{.Names}}' | grep -Eq "^${container_name}\$"; then | ||
| echo "Removing existing Cosmos DB Emulator container: $container_name" | ||
| docker rm -f "$container_name" | ||
| fi | ||
|
|
||
| echo "Starting Cosmos DB Emulator container on port $port with HTTPS..." | ||
| docker run -d \ | ||
| --name "$container_name" \ | ||
| --publish "${port}:8081" \ | ||
| "$image" \ | ||
| --protocol https \ | ||
| --enable-explorer false | ||
AndriySvyryd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| echo "Waiting for emulator to be ready (up to ~$((max_retries * retry_delay))s)..." | ||
| ready=false | ||
| for i in $(seq 1 "$max_retries"); do | ||
| sleep "$retry_delay" | ||
| if curl -ks --connect-timeout "$retry_delay" --max-time "$retry_delay" "https://localhost:${port}/" -o /dev/null; then | ||
| ready=true | ||
| echo "Cosmos DB Emulator is ready." | ||
| break | ||
| fi | ||
| echo " Attempt $i/$max_retries - not ready yet..." | ||
| done | ||
|
|
||
| if [ "$ready" != true ]; then | ||
| echo "Emulator did not become ready. Container logs:" | ||
| docker logs "$container_name" | ||
| docker stop "$container_name" 2>/dev/null || true | ||
| docker rm -f "$container_name" 2>/dev/null || true | ||
| exit 1 | ||
| fi | ||
|
|
||
| exit 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.