-
Notifications
You must be signed in to change notification settings - Fork 43
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
Rerunning tests causes them to fail because the container is not cleaned up. #208
Comments
No, this isn't the expected behavior. Each new container starts an independent instance (until any customizations are made - like mounting postgres data or reusing the same container)
Even if it's not cleaned up (e.g Could you share the code that causes the issue? How do you connect to postgres? |
While moving all the code to a single file, I noticed I was ignoring the This works:
This does not work:
|
Might that be that you have a local postgres instance? (i.e you started a container, but connected to the local one on your machine every time) Because containers are always mapped to the random port (until customized) and that's why you need to use |
I don't think it was connecting to the local instance because deleting the postgres image manually would fix the tests and allow them to run properly again. I tried deleting all the images and containers so I only had one container and one image running, but the tests would still fail, due to UNIQUE constraints on the second run, when not specifying the port. |
When you don't specify a port in connection string, in fact (depending on the client, ofc) all that happens is usually the default ( |
As you can probably tell I'm not much of an expert with docker and containers. I used I'm not sure why using the port returned by Btw, removing the port again from the connection string causes the issue to happen again. If you want me to run any tests or try out anything let me know I would be happy to help. |
However this parts sounds interesting and weird. Could you try to check what's bound to lsof -i tcp:5432 Also, what you can check is |
I ran |
I'm going to close the issue since using However I'm not sure about underlying issues and can't reproduce. Please, feel free to re-open if you want to discuss the issue deeper, but it requires checking your case more deeply (it doesn't happen on 2 of my devices & some servers, so hard to help without allocating more time) |
I'm using the testcontainers-module Postgres container and all tests pass on the first run, but on the second run they fail because when trying to add the rows, the elements already exist causing problems with UNIQUE constraints. Is it expected behavior that the tests make permanent changes to the environment? I thought the whole point of testcontainers was that each test ran in isolation and the environment would be a clean one for each test.
The text was updated successfully, but these errors were encountered: