Spring testcontainer test hangs when trying to simulate no connection to Mongodb #7618
Replies: 3 comments 2 replies
-
Well, you block the network and then call to findAll without handling failures. For that reason, it is hanging out. When you use latency, you know that after certain amount of time it will be gone but not when cutting down the connection. Look at the following example. In my example, I'm using reactor library. |
Beta Was this translation helpful? Give feedback.
-
Yes, based on the debug logs of mongo driver this is what is doing. Yes, I agree that I need to revisit both spring data implementation and also the mongo driver. I suspect that this behaviour is from the java mongo driver. Other idee is to set timeout to 5s and latency to 6s. This way I have my timeout and also the restoration of the network. |
Beta Was this translation helpful? Give feedback.
-
Based on the Toxiproxy documentation, there is the down toxic (https://github.com/Shopify/toxiproxy#down): by disabling the proxy no traffic will be routed. In java Toxiproxy client library there are some methods to enable and disable the proxy: https://github.com/trekawek/toxiproxy-java/blob/7c5ffc5d7aa4780bd2ea73ad945f0227793a7e3d/src/main/java/eu/rekawek/toxiproxy/Proxy.java#L70-L76 Thus, the mentioned failed test will be rewritten as:
|
Beta Was this translation helpful? Give feedback.
-
I'm trying to simulate that the Mongo database is down when the query is run. I'm using testcontainers with Toxiproxy and Mongo.
In the below test class, test called withLatency work as expected but test withoutConnection is hanging.
Code:
The properties file contains:
The test:
When the test is hanging I see in the logs a timeout from the driver:
com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message
Is there something wrong in my config or is this a testcontainer bug?
Beta Was this translation helpful? Give feedback.
All reactions