Issues with reuse, .NET test containers and SQL Server on windows/docker desktop/nunit4 #1525
-
Hi, I'm trying to switch our build running integration tests from using docker from a script to using testcontainers. If I create our containers in the [OneTimeTestSetup] for our integrations tests like this everything works: However it is extremely slow due to have to run a full set of migrations every time. I switched to trying to use .Reuse : This works for some tests but not others. I get errors like this: The container is disposed after each test set which is I presume causing the shutdown? I've tried all sorts of different wait strategies but with zero luck too. Is there a way to do this? Our pipeline times out after an hour so I need some reuse if I'm to switch to testcontainers. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Don't dispose explicitly, otherwise the container will stop. But this isn't really the intended use case for reuse, especially not in CI. You still need to think about your test (session) lifecycle. When are instances shared across tests, when aren't they, which tests are destructive (e.g. modify data), and which aren't, etc.?
So this must have already been an issue back then, right? Or how did you handle the slowness when using scripts? Here's what I'd do:
If that's still too slow, I'd cache the database migration and build specific images so I don't have to run the full migration every time. Some CI providers also support file caching, which you can use to cache an image with the migration pre-applied. |
Beta Was this translation helpful? Give feedback.
Don't dispose explicitly, otherwise the container will stop.
But this isn't really the intended use case for reuse, especially not in CI. You still need to think about your test (session) lifecycle. When are instances shared across tests, when aren't they, which tests are destructive (e.g. modify data), and which aren't, etc.?
So this must have already been an issue back then, right? Or how did you handle the slowness when using scripts?
Here's …