testcontainers / testcontainers-dotnet

A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
https://dotnet.testcontainers.org
MIT License
3.65k stars 250 forks source link

Adding MongoDb replica set support #1196

Open artiomchi opened 3 weeks ago

artiomchi commented 3 weeks ago

What does this PR do?

Adding an option to initialise MongoDb as a single node replica set.

To do this we need a keyfile generated with limited permissions, and add a wait strategy which will initialise the replica set on startup

Why is it important?

Some application would expect the Mongo server to be running in a replica set to improve resiliency, and would set read/write strategies on their commands, which will fail if a replica set is not initialised.

Related issues

There is already an open discussion about it, with some suggestions but no working solution. This PR provides a working implementation and closes #1154

How to test this PR

The single node replica set should behave mostly the same as a single mongo instance.

When running in a replica set, you can also call rs commands to get the status of the replica set.

e.g. the rs.status() command will display the status of the replica set.

netlify[bot] commented 3 weeks ago

Deploy Preview for testcontainers-dotnet ready!

Name Link
Latest commit fe2887e13882c1d44fb8638d91ac5a5d593ff0c1
Latest deploy log https://app.netlify.com/sites/testcontainers-dotnet/deploys/666ff268e77bc600070bed61
Deploy Preview https://deploy-preview-1196--testcontainers-dotnet.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

artiomchi commented 3 weeks ago

The last test run should have been green, but somehow the container has crashed/stopped? Could someone try and re-run the last test run to see if it was an issue in the GitHub runner?

artiomchi commented 2 weeks ago

@HofmeisterAn I managed to re-run the tests- looks like an intermittent issue in GitHub actions. The tests are green now, and I've been using this code in my integration tests already

Let me know if anything else is needed to have this merged

HofmeisterAn commented 2 weeks ago

Thank you for the pull request 🙏. I will try to test and review it in the coming days. I am aware there are a couple of module pull requests waiting to be reviewed. I have not forgotten them; I am addressing them one by one, prioritizing potential bugs and features that benefit the base library.

artiomchi commented 2 weeks ago

No rush, thank you very much @HofmeisterAn!