Skip to content

Commit 0998b25

Browse files
committed
integration tests: vnext cosmosdb emulator
the next generation of cosmosdb is supposed to be more efficient as the current one. local tests with this generation showed lower CPU usage and also does not require partition configuration. Signed-off-by: Gerd Oberlechner <goberlec@redhat.com>
1 parent d2bf7e0 commit 0998b25

File tree

3 files changed

+10
-48
lines changed

3 files changed

+10
-48
lines changed

test-integration/hack/_emulator_handling.sh

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,18 @@ stop_emulator() {
4949
${CONTAINER_RUNTIME} ps -aq --filter "name=local-cosmos-emulator-*" | xargs -r "${CONTAINER_RUNTIME}" rm
5050
}
5151

52-
# Start the emulator container and wait until ready (handles OS differences internally)
52+
# Start the emulator container and wait until ready
5353
start_emulator() {
5454
local container_name=$1
55-
local partition_count=$2
56-
local os_type
57-
local container_image
58-
local ready_log_message
59-
60-
os_type=$(uname -s)
61-
container_image="mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest"
62-
ready_log_message="Started $((partition_count+1))/$((partition_count+1)) partitions"
63-
64-
if [ "${os_type}" = "Darwin" ]; then
65-
# on OSX we need to use the vnext-preview image because the regular one does not support ARM64
66-
# and also fails when running in qemu emulation mode under podman.
67-
# vnext-preview docs: https://learn.microsoft.com/en-gb/azure/cosmos-db/emulator-linux#docker-commands
68-
container_image="mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview"
69-
# the vnext-preview image logs a different message when ready
70-
ready_log_message="PostgreSQL and pgcosmos extension are ready"
71-
fi
55+
# vnext-preview docs: https://learn.microsoft.com/en-gb/azure/cosmos-db/emulator-linux#docker-commands
56+
local container_image="mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview"
57+
local ready_log_message="PostgreSQL and pgcosmos extension are ready"
7258

7359
echo "Starting Cosmos DB emulator with container name: ${container_name}"
7460
${CONTAINER_RUNTIME} run \
7561
--publish 8081:8081 \
7662
--publish 10250-10255:10250-10255 \
7763
-e AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=127.0.0.1 \
78-
-e AZURE_COSMOS_EMULATOR_PARTITION_COUNT="${partition_count}" \
7964
-e PROTOCOL=https \
8065
--name "${container_name}" \
8166
--detach \

test-integration/hack/start-cosmos-emulator.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ source "${SCRIPT_DIR}/_emulator_handling.sh"
1010
# Control whether to restart an existing emulator
1111
RESTART_EXISTING_EMULATOR="${RESTART_EXISTING_EMULATOR:-false}"
1212

13-
# Number of partitions to use for the emulator
14-
# Increase if a lot of tests run in parallel and start failing with 503 errors
15-
# AI claims
16-
# The default total partition count for the Azure Cosmos DB emulator is 25. Increasing
17-
PARTITION_COUNT="${PARTITION_COUNT:-25}"
18-
1913
RUNNING_CONTAINER=$(get_running_emulator_container_name)
2014
if [ -n "${RUNNING_CONTAINER}" ]; then
2115
if [ "${RESTART_EXISTING_EMULATOR}" != "true" ]; then
@@ -31,4 +25,4 @@ if [ -n "${RUNNING_CONTAINER}" ]; then
3125
fi
3226

3327
CONTAINER_NAME="local-cosmos-emulator-$(shuf -i 1000-9999 -n 1)"
34-
start_emulator "${CONTAINER_NAME}" "${PARTITION_COUNT}"
28+
start_emulator "${CONTAINER_NAME}"

test-integration/utils/integrationutils/cosmos_testinfo.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import (
2929
"testing"
3030
"time"
3131

32-
"k8s.io/apimachinery/pkg/util/sets"
33-
3432
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
3533
azcorearm "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
3634
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
@@ -422,20 +420,6 @@ func initializeCosmosDBForFrontend(ctx context.Context, cosmosClient *azcosmos.C
422420
return nil, fmt.Errorf("failed to create database client: %w", err)
423421
}
424422

425-
allContainers := sets.NewString()
426-
allContainersQuery := cosmosDatabaseClient.NewQueryContainersPager("select * from containers c", nil)
427-
for allContainersQuery.More() {
428-
queryResponse, err := allContainersQuery.NextPage(context.Background())
429-
if err != nil {
430-
return nil, utils.TrackError(err)
431-
}
432-
433-
for _, container := range queryResponse.Containers {
434-
allContainers.Insert(container.ID)
435-
}
436-
}
437-
438-
// Create required containers
439423
containers := []struct {
440424
name string
441425
partitionKey string
@@ -449,10 +433,6 @@ func initializeCosmosDBForFrontend(ctx context.Context, cosmosClient *azcosmos.C
449433
start := time.Now()
450434
logger.Info("Create all containers")
451435
for _, container := range containers {
452-
if allContainers.Has(container.name) {
453-
logger.Info("Container already exists", "containerName", container.name)
454-
continue
455-
}
456436
containerProperties := azcosmos.ContainerProperties{
457437
ID: container.name,
458438
PartitionKeyDefinition: azcosmos.PartitionKeyDefinition{
@@ -465,10 +445,13 @@ func initializeCosmosDBForFrontend(ctx context.Context, cosmosClient *azcosmos.C
465445

466446
logger.Info("Creating container", "containerName", container.name)
467447
_, err = cosmosDatabaseClient.CreateContainer(ctx, containerProperties, nil)
468-
if err != nil && !database.IsResponseError(err, http.StatusConflict) {
448+
if err != nil && database.IsResponseError(err, http.StatusConflict) {
449+
logger.Info("Container already exists", "containerName", container.name)
450+
} else if err != nil {
469451
return nil, utils.TrackError(err)
452+
} else {
453+
logger.Info("Container created", "containerName", container.name)
470454
}
471-
logger.Info("Container created", "containerName", container.name)
472455
}
473456
end := time.Now()
474457
logger.Info("All containers created", "duration", end.Sub(start))

0 commit comments

Comments
 (0)