DotNet.Testcontainers.Containers.ResourceReaperException : Initialization has been cancelled. #443
-
Hi @HofmeisterAn! First and foremost, thanks for your this package and great effort in maintaining it! ❤️ I wanted to use public static async Task<IServiceProvider> StartSqlServerTestContainerAsync(this IServiceProvider serviceProvider)
{
var maintenanceContext = serviceProvider.GetRequiredService<MaintenanceContext>();
string connectionString = maintenanceContext.Database.GetConnectionString();
var dbConnectionStringBuilder = new SqlConnectionStringBuilder(connectionString);
int portNumber = int.Parse(dbConnectionStringBuilder.DataSource.Split(",")[1]);
ITestcontainersBuilder<MsSqlTestcontainer> testContainersBuilder
= new TestcontainersBuilder<MsSqlTestcontainer>()
.WithDatabase(new MsSqlTestcontainerConfiguration
{
Password = dbConnectionStringBuilder.Password,
Port = portNumber
})
.WithName("maintenance")
.WithImage("mcr.microsoft.com/mssql/server:2019-CU15-ubuntu-20.04");
MsSqlTestcontainer dbTestContainer = testContainersBuilder.Build();
try
{
await dbTestContainer.StartAsync();
}
catch (Exception)
{
throw;
}
return serviceProvider;
} Then used in the following method: public async Task Setup()
{
await Services.StartSqlServerTestContainerAsync();
Services.RunEfCoreMigrations();
} When running My setup is: Docker Desktop, Linux containers, WSL2. I assume that when a container with What's more interesting, when there's no image of I wonder about the possible cause of such a scenario? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
It seems like you're having an issue I saw a few times in the past too. Until now, I couldn't reproduce it. Maybe we can figure it out together. Do you use the latest beta release?
You'll get this exception if Testcontainers can't establish a connection to the Resource Reaper (Ryuk) within 10 seconds. Testcontainers starts with the first container, the Resource Reaper, in the background. Can you start the Resource Reaper in advance: await ResourceReaper.GetAndStartDefaultAsync()
.ConfigureAwait(false); to check if the connection works at all? This may cancel your test: |
Beta Was this translation helpful? Give feedback.
It seems like you're having an issue I saw a few times in the past too. Until now, I couldn't reproduce it. Maybe we can figure it out together. Do you use the latest beta release?
You'll get this exception if Testcontainers can't establish a connection to the Resource Reaper (Ryuk) within 10 seconds.
https://github.com/HofmeisterAn/dotnet-testcontainers/blob/b99957969f1bf8d1615196f1a77899cb5d51c76e/src/DotNet.Testcontainers/Containers/ResourceReaper.cs#L229
Testcontainers starts with the first container, the Resource Reaper, in the background. Can you start the Resource …