Skip to content

Commit

Permalink
fix: Do not dispose already removed (test) resource
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Apr 27, 2024
1 parent d5552d0 commit 91bc71a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ await Task.WhenAll(container.StartAsync(), network.CreateAsync(), volume.CreateA

public Task DisposeAsync()
{
return Task.WhenAll(_disposables.Select(disposable =>
{
// We do not want to leak resources, but `WithCleanUp(true)` cannot be used
// alongside `WithReuse(true)`. As a workaround, we set the `SessionId` using
// reflection afterward to delete the container, network, and volume.
disposable.AsDynamic()._configuration.SessionId = ResourceReaper.DefaultSessionId;
return disposable.DisposeAsync().AsTask();
}));
return Task.WhenAll(_disposables
.Take(3)
.Select(disposable =>
{
// We do not want to leak resources, but `WithCleanUp(true)` cannot be used
// alongside `WithReuse(true)`. As a workaround, we set the `SessionId` using
// reflection afterward to delete the container, network, and volume.
disposable.AsDynamic()._configuration.SessionId = ResourceReaper.DefaultSessionId;
return disposable.DisposeAsync().AsTask();
}));
}

public void Dispose()
Expand Down

0 comments on commit 91bc71a

Please sign in to comment.