However when I run these in NCrunch I noticed that A) a new instance of Ryuk are started each time the tests are run, and B) every instances of Ryuk is never get stopped/removed, so they will continue growing and consuming more resources.
I looked at the documentation for atomicity, but that seems to be advice for atomicity between tests during a test run and does not track the state between test runs. I tried the "public static int TimesEnvironmentSetUp = 0;" example but each time the tests are run it resets it back to 0 which doesn't seem helpful in this scenario.. but maybe I am missing something here as well?
Here is a simplified example of my issue. Running this test multiple times will result in multiple docker containers being created that will not go away until NCrunch is restarted
using Microsoft.Data.SqlClient;
using Testcontainers.MsSql;
using Xunit;
namespace MyTestProject;
public class ApplicationFactory : IAsyncLifetime
{
public MsSqlContainer SqlContainer;
public async Task InitializeAsync()
{
SqlContainer = new MsSqlBuilder().Build();
await SqlContainer.StartAsync();
}
public async Task DisposeAsync() => await SqlContainer.DisposeAsync();
}
public class TestClass(ApplicationFactory factory) : IClassFixture<ApplicationFactory>
{
[Fact]
public void Should_verify_connection()
{
using var conn = new SqlConnection(factory.SqlContainer.GetConnectionString());
conn.Open();
conn.Close();
}
}
Package and environment versions:
- NCrunch 4.16.0.4
- Visual Studio 17.9.0
- xunit 2.7.0
- Testcontainers.MsSql 3.7.0
- MsSql docker image tag 2019-CU18-ubuntu-20.04