Skip to content

Commit

Permalink
chore: Cleanup resources in ReusableResourceTest
Browse files Browse the repository at this point in the history
Fixes #1157
  • Loading branch information
0xced committed Apr 26, 2024
1 parent 619233a commit 78f147f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0"/>
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="1.1.1"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4"/>
<PackageVersion Include="ReflectionMagic" Version="5.0.1"/>
<PackageVersion Include="SharpZipLib" Version="1.4.2"/>
<PackageVersion Include="SSH.NET" Version="2023.0.0"/>
<PackageVersion Include="System.Text.Json" Version="6.0.9"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ await Task.WhenAll(container.StartAsync(), network.CreateAsync(), volume.CreateA

public Task DisposeAsync()
{
// We don't want to leak resources, but .WithReuse(true).WithCleanUp(true) is not supported.
// So we cheat by setting a non-empty SessionId in order DisposeAsyncCore to delete the container, network and volume.
Enumerable.Range(0, 3).ToList().ForEach(i => _disposables[i].AsDynamic()._configuration.SessionId = ResourceReaper.DefaultSessionId);
return Task.WhenAll(_disposables.Select(disposable => disposable.DisposeAsync().AsTask()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="Microsoft.Extensions.Diagnostics.Testing"/>
<PackageReference Include="coverlet.collector"/>
<PackageReference Include="ReflectionMagic" />
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="xunit"/>
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions tests/Testcontainers.Platform.Linux.Tests/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
global using JetBrains.Annotations;
global using Microsoft.Extensions.Logging.Abstractions;
global using Microsoft.Extensions.Logging.Testing;
global using ReflectionMagic;
global using Xunit;

0 comments on commit 78f147f

Please sign in to comment.