diff --git a/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs b/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs index b25393ab4..d40116625 100644 --- a/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs +++ b/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs @@ -45,7 +45,7 @@ protected override CosmosDbBuilder Init() return base.Init() .WithImage(CosmosDbImage) .WithPortBinding(CosmosDbPort, true) - .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("Started\\r?\\n")); + .WithWaitStrategy(Wait.ForUnixContainer().AddCustomWaitStrategy(new WaitUntil())); } /// @@ -65,4 +65,33 @@ protected override CosmosDbBuilder Merge(CosmosDbConfiguration oldValue, CosmosD { return new CosmosDbBuilder(new CosmosDbConfiguration(oldValue, newValue)); } + + /// + private sealed class WaitUntil : IWaitUntil + { + /// + public async Task UntilAsync(IContainer container) + { + // CosmosDB's preconfigured HTTP client will redirect the request to the container. + const string requestUri = "https://localhost/_explorer/emulator.pem"; + + var httpClient = ((CosmosDbContainer)container).HttpClient; + + try + { + using var httpResponse = await httpClient.GetAsync(requestUri) + .ConfigureAwait(false); + + return httpResponse.IsSuccessStatusCode; + } + catch (Exception) + { + return false; + } + finally + { + httpClient.Dispose(); + } + } + } } \ No newline at end of file