Skip to content
Open
Show file tree
Hide file tree
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
28 changes: 10 additions & 18 deletions test-integration/hack/_emulator_handling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,25 @@ stop_emulator() {
${CONTAINER_RUNTIME} ps -aq --filter "name=local-cosmos-emulator-*" | xargs -r "${CONTAINER_RUNTIME}" rm
}

# Start the emulator container and wait until ready (handles OS differences internally)
# Start the emulator container and wait until ready
start_emulator() {
local container_name=$1
local partition_count=$2
local os_type
local container_image
local ready_log_message

os_type=$(uname -s)
container_image="mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest"
ready_log_message="Started $((partition_count+1))/$((partition_count+1)) partitions"

if [ "${os_type}" = "Darwin" ]; then
# on OSX we need to use the vnext-preview image because the regular one does not support ARM64
# and also fails when running in qemu emulation mode under podman.
# vnext-preview docs: https://learn.microsoft.com/en-gb/azure/cosmos-db/emulator-linux#docker-commands
container_image="mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview"
# the vnext-preview image logs a different message when ready
ready_log_message="PostgreSQL and pgcosmos extension are ready"
# vnext-preview docs: https://learn.microsoft.com/en-gb/azure/cosmos-db/emulator-linux#docker-commands
local container_image="mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview"
local ready_log_message="PostgreSQL and pgcosmos extension are ready"

# The vnext image has a /home/nonroot dir owned by UID 65532 which rootless
# podman in OpenShift CI cannot map. The emulator doesn't use it, so ignoring
# the chown error during pull is safe.
if [ "${CONTAINER_RUNTIME}" = "podman" ]; then
${CONTAINER_RUNTIME} pull --storage-opt ignore_chown_errors=true "${container_image}"
fi

echo "Starting Cosmos DB emulator with container name: ${container_name}"
${CONTAINER_RUNTIME} run \
--publish 8081:8081 \
--publish 10250-10255:10250-10255 \
-e AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=127.0.0.1 \
-e AZURE_COSMOS_EMULATOR_PARTITION_COUNT="${partition_count}" \
-e PROTOCOL=https \
--name "${container_name}" \
--detach \
Expand Down
8 changes: 1 addition & 7 deletions test-integration/hack/start-cosmos-emulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ source "${SCRIPT_DIR}/_emulator_handling.sh"
# Control whether to restart an existing emulator
RESTART_EXISTING_EMULATOR="${RESTART_EXISTING_EMULATOR:-false}"

# Number of partitions to use for the emulator
# Increase if a lot of tests run in parallel and start failing with 503 errors
# AI claims
# The default total partition count for the Azure Cosmos DB emulator is 25. Increasing
PARTITION_COUNT="${PARTITION_COUNT:-25}"

RUNNING_CONTAINER=$(get_running_emulator_container_name)
if [ -n "${RUNNING_CONTAINER}" ]; then
if [ "${RESTART_EXISTING_EMULATOR}" != "true" ]; then
Expand All @@ -31,4 +25,4 @@ if [ -n "${RUNNING_CONTAINER}" ]; then
fi

CONTAINER_NAME="local-cosmos-emulator-$(shuf -i 1000-9999 -n 1)"
start_emulator "${CONTAINER_NAME}" "${PARTITION_COUNT}"
start_emulator "${CONTAINER_NAME}"
27 changes: 5 additions & 22 deletions test-integration/utils/integrationutils/cosmos_testinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
"testing"
"time"

"k8s.io/apimachinery/pkg/util/sets"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
azcorearm "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
Expand Down Expand Up @@ -422,20 +420,6 @@ func initializeCosmosDBForFrontend(ctx context.Context, cosmosClient *azcosmos.C
return nil, fmt.Errorf("failed to create database client: %w", err)
}

allContainers := sets.NewString()
allContainersQuery := cosmosDatabaseClient.NewQueryContainersPager("select * from containers c", nil)
Copy link
Collaborator Author

@geoberle geoberle Feb 21, 2026

Choose a reason for hiding this comment

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

NewQueryContainersPager is not supported in vnext
we can rely on cosmosDatabaseClient.CreateContainer to give us a StatusConflict in case the container exists already

for allContainersQuery.More() {
queryResponse, err := allContainersQuery.NextPage(context.Background())
if err != nil {
return nil, utils.TrackError(err)
}

for _, container := range queryResponse.Containers {
allContainers.Insert(container.ID)
}
}

// Create required containers
containers := []struct {
name string
partitionKey string
Expand All @@ -449,10 +433,6 @@ func initializeCosmosDBForFrontend(ctx context.Context, cosmosClient *azcosmos.C
start := time.Now()
logger.Info("Create all containers")
for _, container := range containers {
if allContainers.Has(container.name) {
logger.Info("Container already exists", "containerName", container.name)
continue
}
containerProperties := azcosmos.ContainerProperties{
ID: container.name,
PartitionKeyDefinition: azcosmos.PartitionKeyDefinition{
Expand All @@ -465,10 +445,13 @@ func initializeCosmosDBForFrontend(ctx context.Context, cosmosClient *azcosmos.C

logger.Info("Creating container", "containerName", container.name)
_, err = cosmosDatabaseClient.CreateContainer(ctx, containerProperties, nil)
if err != nil && !database.IsResponseError(err, http.StatusConflict) {
if err != nil && database.IsResponseError(err, http.StatusConflict) {
logger.Info("Container already exists", "containerName", container.name)
} else if err != nil {
return nil, utils.TrackError(err)
} else {
logger.Info("Container created", "containerName", container.name)
}
logger.Info("Container created", "containerName", container.name)
}
end := time.Now()
logger.Info("All containers created", "duration", end.Sub(start))
Expand Down