Closed diegosasw closed 5 months ago
This is not a bug. Use the provided and preconfigured HTTP client:
There are plenty of similar issues. Please double-check the search results. They should contain further explanations.
Thank you, yes you're right. That works well.
https://github.com/diegosasw/cosmosdb-sample/commit/7c53b29a7bc506936932aa6fc329392e51f4abb0
Testcontainers version
3.9.0
Using the latest Testcontainers version?
Yes
Host OS
Windows
Host arch
x64
.NET version
8.0.302
Docker version
Docker info
What happened?
Attempts to create a database in the CosmosDb emulator running as a Testcontainer aren't successful due to hanging indefinitely. No error or exception.
The container spins up correctly with random ports, and it returns the connection string (e.g:
AccountEndpoint=https://127.0.0.1:50676/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
).When using the cosmos client with SSL validation, it throws the expected
HttpRequestException
(see reproducible repository). When using the cosmos client without SSL validation, it hangs trying to create database.This is the container I use. Please see more details below in the additional information along with the repository to reproduce the problem and to compare it with Ductus Fluent Docker (which works well for the same scenario).
Relevant log output
No response
Additional information
I have reproduced the error in this simple solution https://github.com/diegosasw/cosmosdb-sample/tree/21ecf563f0329fbb60a7fb67d9ffc14009237e27
To reproduce, simply clone the repository provided there is .NET 8 and Docker daemon available. Compile with
and run tests with
3 out of 4 tests will pass.
Basically I have configured two xUnit fixtures to demonstrate it.
FluentDockerFixture
- which spins up a CosmosDb emulator using FluentDocker, and stops it and deletes it when the tests endTestContainerFixture
- which spins up the testcontainer CosmosDb emulator.Then there are two test classes (i.e: two
IClassFixture
), each one using its cosmos db fixture. The same scenarios Each test class tests two things:Secure_Client_Should_Fail
which attempts to create a database validating the untrusted SSL and expects to fail. It works well for both CosmosDb containers.Insecure_Client_Should_Succeed
which attempts to create a database without validating the untrusted SSL and expects to succeed. This one works fine for the CosmosDb container created with Fluent Docker, but fails with Testcontainer because it never ends, it hangs indefinitely (I suppose it eventually times out).This is the code which can be found in the public repository.
The fixture
The tests
PS: The tests run sequentially (see
xunit.runner.json
because if they run in parallel the 4 tests will succeed (probably due to the problematic test reaching the other Fluent Docker CosmosDb container, but not sure). I tried to debug with"maxParallelThreads": 0
and"maxParallelThreads": 1
to see why it was succeeding when running in parallel and whether the test was creating the database in the other container in 8081, but when debugging the tests run sequentially, so I couldn't reveal this mystery. In any case, the original problem remains.