Connection Refused: Azure Cosmos DB Testcontainers in GitLab

284 views Asked by At

I have successfully used SQL Server/PostgreSQL/MongoDB Testcontainers in GitLab pipelines using exactly the same approach. But the Cosmos DB emulator wants to be special. This is the error it throws:

System.Net.Http.HttpRequestException : Connection refused (127.0.0.1:8081)

Why does it refuse the connection? What is necessary to get this running?

GlobalUsings.cs

global using Xunit;
global using System.Net;
global using CosmosDb.API.Models;
global using DotNet.Testcontainers.Builders;
global using FluentAssertions;
global using Microsoft.Azure.Cosmos;
global using Testcontainers.CosmosDb;

CosmosDbTestcontainersTests.cs

namespace CosmosDb.Unit.Tests;

public class CosmosDbTestcontainersTests : IAsyncLifetime
{
    private CosmosDbContainer _cosmosDbContainer = new CosmosDbBuilder()
        .WithImage("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator")
        .WithName("Cosmos_DB")
        .WithPortBinding(8081, 8081)
        .WithPortBinding(10251, 10251)
        .WithPortBinding(10252, 10252)
        .WithPortBinding(10253, 10253)
        .WithPortBinding(10254, 10254)
        .WithEnvironment("AZURE_COSMOS_EMULATOR_PARTITION_COUNT", "3")
        .WithEnvironment("AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE", "127.0.0.1")
        .WithEnvironment("AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE", "false")
        .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(8081)).Build();

    [Fact]
    public async void CreateDatabase_Testcontainers()
    {
        var cosmosClientOptions = new CosmosClientOptions
        {
            ServerCertificateCustomValidationCallback = (_, _, _) => true,
            ConnectionMode = ConnectionMode.Direct
        };

        var cosmosClient = new CosmosClient(connectionString: _cosmosDbContainer.GetConnectionString(),
            clientOptions: cosmosClientOptions);

        var databaseResponse = await cosmosClient.CreateDatabaseIfNotExistsAsync(id: "HotelsDatabase");
        databaseResponse.StatusCode.Should().BeOneOf(HttpStatusCode.Created, HttpStatusCode.OK);
    }

    public async Task InitializeAsync()
    {
        await _cosmosDbContainer.StartAsync();
    }

    public async Task DisposeAsync()
    {
        await _cosmosDbContainer.StopAsync();
    }
}

.gitlab-ci.yml

image: mcr.microsoft.com/dotnet/sdk:6.0

variables:
  OBJECTS_DIRECTORY: 'obj'
  NUGET_PACKAGES_DIRECTORY: '.nuget'
  SOURCE_CODE_PATH: '*/*/'
  DOCKER_HOST: "tcp://docker:2375"
  DOCKER_TLS_CERTDIR: ""
  DOCKER_DRIVER: overlay2
  FF_NETWORK_PER_BUILD: 'true'

cache:
  key: "$CI_JOB_STAGE-$CI_COMMIT_REF_SLUG"
  paths:
    - '$SOURCE_CODE_PATH$OBJECTS_DIRECTORY/project.assets.json'
    - '$SOURCE_CODE_PATH$OBJECTS_DIRECTORY/*.csproj.nuget.*'
    - '$NUGET_PACKAGES_DIRECTORY'

services:
  - name: docker:dind
    command: [ "--tls=false" ]

before_script:
  - 'dotnet restore --packages $NUGET_PACKAGES_DIRECTORY'

build:
  stage: build
  script:
    - 'dotnet build --no-restore'

tests:
  stage: test
  script:
    - 'dotnet test --no-restore'

GitLab pipeline output for test stage

[0KRunning with gitlab-runner 16.3.0~beta.108.g2b6048b4 (2b6048b4)[0;m
[0K  on green-2.saas-linux-small-amd64.runners-manager.gitlab.com/default ns46NMmJ, system ID: s_85d7af184313[0;m
[0K  feature flags: FF_NETWORK_PER_BUILD:true, FF_USE_IMPROVED_URL_MASKING:true, FF_RESOLVE_FULL_TLS_CHAIN:false[0;m
section_start:1697801715:prepare_executor
[0K[0K[36;1mPreparing the "docker+machine" executor[0;m[0;m
[0KUsing Docker executor with image mcr.microsoft.com/dotnet/sdk:6.0 ...[0;m
[0KStarting service docker:dind ...[0;m
[0KPulling docker image docker:dind ...[0;m
[0KUsing docker image sha256:114405a05c1ea1579eada94100ea1262ec351ce96625fed47684ed05ef48f52f for docker:dind with digest docker@sha256:0752ca4e936da012c173c119217c0f9599b3b191c1557e53206d5d06d2627580 ...[0;m
[0KWaiting for services to be up and running (timeout 30 seconds)...[0;m
[0KPulling docker image mcr.microsoft.com/dotnet/sdk:6.0 ...[0;m
[0KUsing docker image sha256:d67283e5fcfa5562db0c093604838eda3c23fd1e5f5a8b0df924888c44e81578 for mcr.microsoft.com/dotnet/sdk:6.0 with digest mcr.microsoft.com/dotnet/sdk@sha256:1167d21bf2d6b0aeb9fce863a73e90defa9233574b74d9deabee0a714f15c951 ...[0;m
section_end:1697801740:prepare_executor
[0Ksection_start:1697801740:prepare_script
[0K[0K[36;1mPreparing environment[0;m[0;m
Running on runner-ns46nmmj-project-51412685-concurrent-0 via runner-ns46nmmj-s-l-s-amd64-1697801596-9ad7ba6a...
section_end:1697801746:prepare_script
[0Ksection_start:1697801746:get_sources
[0K[0K[36;1mGetting source from Git repository[0;m[0;m
[32;1mFetching changes with git depth set to 20...[0;m
Initialized empty Git repository in /builds/cheerful-penguin/cosmos-db/.git/
[32;1mCreated fresh repository.[0;m
[32;1mChecking out 2d8e5093 as detached HEAD (ref is trunk)...[0;m

[32;1mSkipping Git submodules setup[0;m
[32;1m$ git remote set-url origin "${CI_REPOSITORY_URL}"[0;m
section_end:1697801747:get_sources
[0Ksection_start:1697801747:restore_cache
[0K[0K[36;1mRestoring cache[0;m[0;m
[32;1mChecking cache for test-trunk-protected...[0;m
[0;33mWARNING: file does not exist                      [0;m 
[0;33mFailed to extract cache[0;m
section_end:1697801747:restore_cache
[0Ksection_start:1697801747:step_script
[0K[0K[36;1mExecuting "step_script" stage of the job script[0;m[0;m
[0KUsing docker image sha256:d67283e5fcfa5562db0c093604838eda3c23fd1e5f5a8b0df924888c44e81578 for mcr.microsoft.com/dotnet/sdk:6.0 with digest mcr.microsoft.com/dotnet/sdk@sha256:1167d21bf2d6b0aeb9fce863a73e90defa9233574b74d9deabee0a714f15c951 ...[0;m
[32;1m$ dotnet restore --packages $NUGET_PACKAGES_DIRECTORY[0;m
  Determining projects to restore...
  Restored /builds/cheerful-penguin/cosmos-db/src/CosmosDb.API/CosmosDb.API.csproj (in 3.52 sec).
  Restored /builds/cheerful-penguin/cosmos-db/test/CosmosDb.Unit.Tests/CosmosDb.Unit.Tests.csproj (in 3.52 sec).
[32;1m$ dotnet test --no-restore[0;m
/builds/cheerful-penguin/cosmos-db/src/CosmosDb.API/Models/HotelModel.cs(6,19): warning CS8618: Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [/builds/cheerful-penguin/cosmos-db/src/CosmosDb.API/CosmosDb.API.csproj]
/builds/cheerful-penguin/cosmos-db/src/CosmosDb.API/Models/HotelModel.cs(7,19): warning CS8618: Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [/builds/cheerful-penguin/cosmos-db/src/CosmosDb.API/CosmosDb.API.csproj]
  CosmosDb.API -> /builds/cheerful-penguin/cosmos-db/src/CosmosDb.API/bin/Debug/net6.0/CosmosDb.API.dll
  CosmosDb.Unit.Tests -> /builds/cheerful-penguin/cosmos-db/test/CosmosDb.Unit.Tests/bin/Debug/net6.0/CosmosDb.Unit.Tests.dll
Test run for /builds/cheerful-penguin/cosmos-db/test/CosmosDb.Unit.Tests/bin/Debug/net6.0/CosmosDb.Unit.Tests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.3.3 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[testcontainers.org 00:00:00.08] Connected to Docker:
  Host: tcp://docker:2375/
  Server Version: 24.0.6
  Kernel Version: 5.4.109+
  API Version: 1.43
  Operating System: Alpine Linux v3.18 (containerized)
  Total Memory: 7.78 GB
[testcontainers.org 00:00:00.19] Docker config "/root/.docker/config.json" not found
[testcontainers.org 00:00:00.19] Searching Docker registry credential in Auths
[testcontainers.org 00:00:00.19] Docker registry credential https://index.docker.io/v1/ not found
[testcontainers.org 00:00:01.44] Docker image testcontainers/ryuk:0.5.1 created
[testcontainers.org 00:00:03.10] Docker container b3db029c8139 created
[testcontainers.org 00:00:03.15] Start Docker container b3db029c8139
[testcontainers.org 00:00:03.37] Wait for Docker container b3db029c8139 to complete readiness checks
[testcontainers.org 00:00:03.38] Docker container b3db029c8139 ready
[testcontainers.org 00:00:03.39] Docker config "/root/.docker/config.json" not found
[testcontainers.org 00:00:03.39] Searching Docker registry credential in Auths
[testcontainers.org 00:00:03.39] Docker registry credential mcr.microsoft.com not found
[testcontainers.org 00:00:29.38] Docker image mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest created
[testcontainers.org 00:00:31.92] Docker container d4b29e02446d created
[testcontainers.org 00:00:31.92] Start Docker container d4b29e02446d
[testcontainers.org 00:00:32.19] Wait for Docker container d4b29e02446d to complete readiness checks
[testcontainers.org 00:00:32.20] Execute "/bin/sh -c true && (grep -i ':0*1F91' /proc/net/tcp* || nc -vz -w 1 localhost 8081 || /bin/bash -c '</dev/tcp/localhost/8081')" at Docker container d4b29e02446d
[testcontainers.org 00:00:33.30] Execute "/bin/sh -c true && (grep -i ':0*1F91' /proc/net/tcp* || nc -vz -w 1 localhost 8081 || /bin/bash -c '</dev/tcp/localhost/8081')" at Docker container d4b29e02446d
[testcontainers.org 00:00:34.37] Execute "/bin/sh -c true && (grep -i ':0*1F91' /proc/net/tcp* || nc -vz -w 1 localhost 8081 || /bin/bash -c '</dev/tcp/localhost/8081')" at Docker container d4b29e02446d
[testcontainers.org 00:00:35.43] Execute "/bin/sh -c true && (grep -i ':0*1F91' /proc/net/tcp* || nc -vz -w 1 localhost 8081 || /bin/bash -c '</dev/tcp/localhost/8081')" at Docker container d4b29e02446d
[testcontainers.org 00:00:36.53] Execute "/bin/sh -c true && (grep -i ':0*1F91' /proc/net/tcp* || nc -vz -w 1 localhost 8081 || /bin/bash -c '</dev/tcp/localhost/8081')" at Docker container d4b29e02446d
[testcontainers.org 00:00:37.66] Execute "/bin/sh -c true && (grep -i ':0*1F91' /proc/net/tcp* || nc -vz -w 1 localhost 8081 || /bin/bash -c '</dev/tcp/localhost/8081')" at Docker container d4b29e02446d
[testcontainers.org 00:00:38.81] Execute "/bin/sh -c true && (grep -i ':0*1F91' /proc/net/tcp* || nc -vz -w 1 localhost 8081 || /bin/bash -c '</dev/tcp/localhost/8081')" at Docker container d4b29e02446d
[testcontainers.org 00:00:39.95] Execute "/bin/sh -c true && (grep -i ':0*1F91' /proc/net/tcp* || nc -vz -w 1 localhost 8081 || /bin/bash -c '</dev/tcp/localhost/8081')" at Docker container d4b29e02446d
[testcontainers.org 00:00:41.08] Execute "/bin/sh -c true && (grep -i ':0*1F91' /proc/net/tcp* || nc -vz -w 1 localhost 8081 || /bin/bash -c '</dev/tcp/localhost/8081')" at Docker container d4b29e02446d
[testcontainers.org 00:00:42.24] Execute "/bin/sh -c true && (grep -i ':0*1F91' /proc/net/tcp* || nc -vz -w 1 localhost 8081 || /bin/bash -c '</dev/tcp/localhost/8081')" at Docker container d4b29e02446d
[testcontainers.org 00:00:43.41] Execute "/bin/sh -c true && (grep -i ':0*1F91' /proc/net/tcp* || nc -vz -w 1 localhost 8081 || /bin/bash -c '</dev/tcp/localhost/8081')" at Docker container d4b29e02446d
[testcontainers.org 00:00:44.54] Execute "/bin/sh -c true && (grep -i ':0*1F91' /proc/net/tcp* || nc -vz -w 1 localhost 8081 || /bin/bash -c '</dev/tcp/localhost/8081')" at Docker container d4b29e02446d
[testcontainers.org 00:00:44.64] Docker container d4b29e02446d ready
[testcontainers.org 00:04:58.48] Stop Docker container d4b29e02446d
[xUnit.net 00:05:15.66]     CosmosDb.Unit.Tests.CosmosDbTestcontainersTests.CreateDatabase_Testcontainers [FAIL]
  Failed CosmosDb.Unit.Tests.CosmosDbTestcontainersTests.CreateDatabase_Testcontainers [4 m 14 s]
  Error Message:
   System.Net.Http.HttpRequestException : Connection refused (127.0.0.1:8081)
---- System.Net.Sockets.SocketException : Connection refused
  Stack Trace:
     at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage request)
   at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Microsoft.Azure.Cosmos.CosmosHttpClientCore.ExecuteHttpHelperAsync(HttpRequestMessage requestMessage, ResourceType resourceType, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.CosmosHttpClientCore.SendHttpHelperAsync(Func`1 createRequestMessageAsync, ResourceType resourceType, HttpTimeoutPolicy timeoutPolicy, IClientSideRequestStatistics clientSideRequestStatistics, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Routing.GatewayAddressCache.GetMasterAddressesViaGatewayAsync(DocumentServiceRequest request, ResourceType resourceType, String resourceAddress, String entryUrl, Boolean forceRefresh, Boolean useMasterCollectionResolver)
   at Microsoft.Azure.Cosmos.Routing.GatewayAddressCache.ResolveMasterAsync(DocumentServiceRequest request, Boolean forceRefresh)
   at Microsoft.Azure.Cosmos.Routing.GatewayAddressCache.TryGetAddressesAsync(DocumentServiceRequest request, PartitionKeyRangeIdentity partitionKeyRangeIdentity, ServiceIdentity serviceIdentity, Boolean forceRefreshPartitionAddresses, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.AddressResolver.ResolveAddressesAndIdentityAsync(DocumentServiceRequest request, Boolean forceRefreshPartitionAddresses, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.AddressResolver.ResolveAsync(DocumentServiceRequest request, Boolean forceRefreshPartitionAddresses, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Routing.GlobalAddressResolver.ResolveAsync(DocumentServiceRequest request, Boolean forceRefresh, CancellationToken cancellationToken)
   at Microsoft.Azure.Documents.AddressSelector.ResolveAddressesAsync(DocumentServiceRequest request, Boolean forceAddressRefresh)
   at Microsoft.Azure.Documents.AddressSelector.ResolveAllTransportAddressUriAsync(DocumentServiceRequest request, Boolean includePrimary, Boolean forceRefresh)
   at Microsoft.Azure.Documents.StoreReader.ReadMultipleReplicasInternalAsync(DocumentServiceRequest entity, Boolean includePrimary, Int32 replicaCountToRead, Boolean requiresValidLsn, Boolean useSessionToken, ReadMode readMode, Boolean checkMinLSN, Boolean forceReadAll)
   at Microsoft.Azure.Documents.StoreReader.ReadMultipleReplicaAsync(DocumentServiceRequest entity, Boolean includePrimary, Int32 replicaCountToRead, Boolean requiresValidLsn, Boolean useSessionToken, ReadMode readMode, Boolean checkMinLSN, Boolean forceReadAll)
   at Microsoft.Azure.Documents.QuorumReader.ReadQuorumAsync(DocumentServiceRequest entity, Int32 readQuorum, Boolean includePrimary, ReadMode readMode)
   at Microsoft.Azure.Documents.QuorumReader.ReadStrongAsync(DocumentServiceRequest entity, Int32 readQuorumValue, ReadMode readMode)
   at Microsoft.Azure.Documents.ReplicatedResourceClient.<>c__DisplayClass31_0.<<InvokeAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.Azure.Documents.RequestRetryUtility.ProcessRequestAsync[TRequest,IRetriableResponse](Func`1 executeAsync, Func`1 prepareRequest, IRequestRetryPolicy`2 policy, CancellationToken cancellationToken, Func`1 inBackoffAlternateCallbackMethod, Nullable`1 minBackoffForInBackoffCallback)
   at Microsoft.Azure.Documents.ShouldRetryResult.ThrowIfDoneTrying(ExceptionDispatchInfo capturedException)
   at Microsoft.Azure.Documents.RequestRetryUtility.ProcessRequestAsync[TRequest,IRetriableResponse](Func`1 executeAsync, Func`1 prepareRequest, IRequestRetryPolicy`2 policy, CancellationToken cancellationToken, Func`1 inBackoffAlternateCallbackMethod, Nullable`1 minBackoffForInBackoffCallback)
   at Microsoft.Azure.Documents.StoreClient.ProcessMessageAsync(DocumentServiceRequest request, CancellationToken cancellationToken, IRetryPolicy retryPolicy)
   at Microsoft.Azure.Cosmos.Handlers.TransportHandler.ProcessMessageAsync(RequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Handlers.TransportHandler.SendAsync(RequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Handlers.RouterHandler.SendAsync(RequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.RequestHandler.SendAsync(RequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Handlers.AbstractRetryHandler.ExecuteHttpRequestAsync(Func`1 callbackMethod, Func`3 callShouldRetry, Func`3 callShouldRetryException, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Handlers.AbstractRetryHandler.ExecuteHttpRequestAsync(Func`1 callbackMethod, Func`3 callShouldRetry, Func`3 callShouldRetryException, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Handlers.AbstractRetryHandler.SendAsync(RequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.RequestHandler.SendAsync(RequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Handlers.DiagnosticsHandler.SendAsync(RequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.RequestHandler.SendAsync(RequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler.SendAsync(RequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler.SendAsync(String resourceUriString, ResourceType resourceType, OperationType operationType, RequestOptions requestOptions, ContainerInternal cosmosContainerCore, FeedRange feedRange, Stream streamPayload, Action`1 requestEnricher, ITrace trace, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.CosmosClient.<>c__DisplayClass54_0.<<CreateDatabaseIfNotExistsAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.Azure.Cosmos.ClientContextCore.RunWithDiagnosticsHelperAsync[TResult](String containerName, String databaseName, OperationType operationType, ITrace trace, Func`2 task, Func`2 openTelemetry, String operationName, RequestOptions requestOptions)
   at Microsoft.Azure.Cosmos.ClientContextCore.<>c__DisplayClass31_0`1.<<OperationHelperWithRootTraceWithSynchronizationContextAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at CosmosDb.Unit.Tests.CosmosDbTestcontainersTests.CreateDatabase_Testcontainers() in /builds/cheerful-penguin/cosmos-db/test/CosmosDb.Unit.Tests/CosmosDbTestcontainersTests.cs:line 30
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
----- Inner Stack Trace -----
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)

Failed!  - Failed:     1, Passed:     0, Skipped:     0, Total:     1, Duration: < 1 ms - /builds/cheerful-penguin/cosmos-db/test/CosmosDb.Unit.Tests/bin/Debug/net6.0/CosmosDb.Unit.Tests.dll (net6.0)
section_end:1697802075:step_script
[0Ksection_start:1697802075:cleanup_file_variables
[0K[0K[36;1mCleaning up project directory and file based variables[0;m[0;m
section_end:1697802075:cleanup_file_variables
[0K[31;1mERROR: Job failed: exit code 1
[0;m
1

There are 1 answers

0
Viktoras Mickūnas On

I don't know if you found a solution to you problem, but what you need to do is to configure CosmosClient to use Gateway mode instead of the default Direct mode, Testcontainers Cosmos DB module needs this :

var cosmosClientOptions = new CosmosClientOptions
{
    ConnectionMode = ConnectionMode.Gateway,

    HttpClientFactory = () => cosmosDbContainer.HttpClient,
};

var connectionString = cosmosDbContainer.GetConnectionString();
var cosmosClient = new CosmosClient(connectionString, cosmosClientOptions);