Closed wilsjame closed 5 months ago
Having the same issue. Last run on Friday succeeded. Todays run on exact same commit fails.
I had a quick look too and can confirm and reproduce the issue. It appears that the Cosmos DB client is not even calling/using the provided HTTP client (that sets the custom validation callback), and the exceptions happen pretty early. Since the module has not changed, and as @WakaToa mentioned, his configuration ran until Friday, I suspect that the image has changed. AFAIK, there is no version we can pin. Probably the best idea is to create an upstream issue.
@HofmeisterAn Can you check what happens if you use the following WaitStrategy?
private class CosmosWaitStrategy : IWaitUntil
{
public async Task<bool> UntilAsync(IContainer container)
{
var uri = new Uri(
$"https://{container.Hostname}:{container.GetMappedPublicPort(CosmosDbBuilder.CosmosDbPort)}/_explorer/emulator.pem");
try
{
using var httpClient = new HttpClient(new HttpClientHandler()
{
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
});
var result = await httpClient.GetAsync(uri);
return result.StatusCode is >= HttpStatusCode.OK and < HttpStatusCode.Ambiguous;
}
catch (Exception e)
{
return false;
}
finally
{
await Task.Delay(1000);
}
}
}
Usage:
this.container = new CosmosDbBuilder()
.WithPrivileged(true)
.WithExposedPort(CosmosDbBuilder.CosmosDbPort)
.WithCleanUp(true)
.WithWaitStrategy(Wait.ForUnixContainer()
.AddCustomWaitStrategy(new CosmosWaitStrategy()))
.Build();
await this.container.StartAsync();
It seems that the Cosmos Emulator is not ready yet when the tests start. The WaitStrategy will wait until it is fully initialized and the certificate is exposed. Its working for me.
Oh, interesting (odd coincidence). Indeed, it works on my machine too. I did something similar yesterday but did not wait long enough. It is super slow. Is it slow on your machine too? I thought it was faster. However, I have not used it much in the past. Are you interested in contributing a fix? I made some changes and used the preconfigured HTTP client. WDYT?
private sealed class WaitUntil : IWaitUntil
{
public async Task<bool> 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();
}
}
}
The wait strategy has been updated (#1109).
Testcontainers version
3.7.0
Using the latest Testcontainers version?
Yes
Host OS
macOS Sonoma Version 14.2.1 (23C71)
Host arch
i386
.NET version
8.0
Docker version
Docker info
What happened?
This line throws an error: SSL connection could not be established.
https://github.com/testcontainers/testcontainers-dotnet/blob/1c80fe80432873a625b2cde7ce52e99308d68b4e/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs#L31
Expected no error and test passes.
Relevant log output
Additional information
833 introduced these changes.