Wie passe ich das Anforderungszeitlimit für CreateContainerifnotexistsAsync an, wenn Sie den Cosmos -DB -Emulator über TC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Wie passe ich das Anforderungszeitlimit für CreateContainerifnotexistsAsync an, wenn Sie den Cosmos -DB -Emulator über T

Post by Anonymous »

In meinem C# Nunit -Testprojekt verwende ich das TestContainer.cosmosDB Nuget -Paket, um einen CosmosDBConnector mit dem CosmosDBBuilder zu erstellen.

Code: Select all

using NUnit;
using Microsoft.Azure.Cosmos;
using Testcontainers.CosmosDb;

public class CosmosIntegrationTests
{
private CosmosDbContainer _cosmosDbContainer;
private CosmosClient _cosmosClient;
private Database _cosmosDatabase;
private Container _cosmosContainer1;
private Container _cosmosContainer2;
private Container _cosmosContainer3;

[OneTimeSetUp]
public async Task OneTimeSetUp()
{

_cosmosDbContainer = new CosmosDbBuilder()
.WithImage("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest")
.WithExposedPort(8081)
.WithPortBinding(8081, true)
.Build();

await _cosmosDbContainer.StartAsync();
Ich erstelle dann einen Cosmosclient mit einem 300 Sekunden -RequestTimeOut und dem CosmosDBContainer.httpclient Um nicht mit dem Emulators -Zertifikat (ebenfalls ein 300 -Sekunden -Timeout) zu handeln, gefolgt von einer neuen Datenbank und 3 contents _cosmosDbContainer.HttpClient;
};

_cosmosClient = new CosmosClient(_cosmosDbContainer.GetConnectionString(), options);

_cosmosDatabase = (await _cosmosClient.CreateDatabaseIfNotExistsAsync($"cosmosdb-{Guid.NewGuid()}")).Database;

_cosmosContainer1 = (await _cosmosDatabase.CreateContainerIfNotExistsAsync("container1", "/id")).Container;
_cosmosContainer2 = (await _cosmosDatabase.CreateContainerIfNotExistsAsync("container2", "/id")).Container;
_cosmosContainer3 = (await _cosmosDatabase.CreateContainerIfNotExistsAsync("container3", "/id")).Container;
}
}
[/code]
Das Problem, das ich beim Ausführen der Tests habe, ist, dass ich manchmal eine microsoft.azure.cosmos.cosmosexception während des Onetimesetups beim Erstellen von "Container3" erhalte. Diese Ausnahme heißt: < /p>

Code: Select all

Response status code does not indicate success: RequestTimeout (408); Substatus: 0; ActivityId: eba582b0-1fdd-449d-b7b2-39b87696d0f7; Reason: (GatewayStoreClient Request Timeout. Start Time UTC:04/09/2025 00:52:17; Total Duration:65003.66 Ms; Request Timeout 65000 Ms; Http Client Timeout:300000 Ms;

Die Auszeit des Aussagens ist das "Anfrage -Timeout", das immer noch eine Einstellung von 65 Sekunden zu haben scheint, während das "HTTP -Client -Timeout" richtig 300 Sekunden zeigt. Eindruck, der nur verwendet wurde, um sicherzustellen, dass das httpclient.timeout nicht geringer sein kann.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post