-
-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Replace CosmosDb module #833
feat: Replace CosmosDb module #833
Conversation
✅ Deploy Preview for testcontainers-dotnet ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for submitting the pull request! I was wondering if you know if any changes were made to the Cosmos DB image or the GH-hosted runners? Cosmos DB did not run properly or was flaky running on Ubuntu-22.04.
I will review your pull request tomorrow. Thank you once again for your contribution!
Hi, unfortunately the emulator is still flaky on some runners due to certain CPUs. Hopefully MS will fix this soon. I still find this useful for Testcontainers since we use Testcontainers when running the tests locally and use a real cosmos container in the pipelines (at least until the issue is fixed). Really hoping MS will fix it soon! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks good. I just have a question about PartitionCount
and IpAddressOverride
.
Could it be possible to integrate the /Port configuration from last comment in #421 to avoid HttpClient exception ? Maybe something in the builder |
If you use the Example: var cosmosDbContainer = new CosmosDbBuilder().Build();
var cosmosClientOptions = new CosmosClientOptions {
ConnectionMode = ConnectionMode.Gateway,
HttpClientFactory = () => cosmosDbContainer.HttpClient
};
var cosmosClient = new CosmosClient(cosmosDbContainer.GetConnectionString(), cosmosClientOptions); |
only if this is the 8081 port used. If not you have to rewrite the url with an HttpMessageHandler or use the /Port argument But the random port will likely not be 8081. |
Yes, the |
I don't know the magic behind :/ The only thing I know is that all the errors disappear when you set /Port=xxx and bind the docker port xxx to the host port xxx as in the second link I provided. It's just a question, because with the last implementation I had the issue and ended by creating my own implementation with the /Port arg |
The container port will always be 8081. We resolve it to the random assigned host port her:
I think the configuration is fine. |
The problem is not the connection string. It's from having a random port assign to 8081. Here is the equivalent of what the builder will produce with a random port mapped to the 8081
And here is what it should be to avoid error
From Microsoft doc and the issue when both port are not the same. And here with some code : The cosmosClientBuilder which doesn't change cosmosClientBuilder.WithHttpClientFactory(
() =>
{
HttpMessageHandler httpMessageHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
};
return new HttpClient(httpMessageHandler);
})
.WithConnectionModeGateway(); The exception I got when the port is mapped 8082:8081
with port mapped 8082:8082 with the /Port argument all work smoothly |
In your above example, you are not using the HttpClient provided by the Testcontainers module. If you did then the code would be: // Create test container
var cosmosDbContainer = new CosmosDbBuilder().Build();
cosmosClientBuilder
.WithHttpClientFactory(() => cosmosDbContainer.HttpClient) // Use http client from Testcontainers module
.WithConnectionModeGateway(); |
It would imply to add the library as reference to the main project or pass down the httpclient which is not needed with the fix I suggest. |
No, as this is a test library then I would normally use dependency injection to inject the |
Nevermind, It was just a suggestion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the back and forth, I was trying to get the tests running on the Windows agent, but that is even more a mess. I think we need to skip the tests for now. I will merge it later in the day.
What does this PR do?
Replaces the old CosmosDb module with the new module format.
Why is it important?
Migrates one of the obsolete modules to the new format.
Related issues
All the CosmosDb tests should pass