diff --git a/Directory.Packages.props b/Directory.Packages.props index 039256594..a00645801 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,6 +10,7 @@ + diff --git a/tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs b/tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs index 6a6f1a228..0c209feb6 100644 --- a/tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs +++ b/tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs @@ -51,7 +51,14 @@ await Task.WhenAll(container.StartAsync(), network.CreateAsync(), volume.CreateA public Task DisposeAsync() { - return Task.WhenAll(_disposables.Select(disposable => disposable.DisposeAsync().AsTask())); + 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(); + })); } public void Dispose() @@ -76,13 +83,18 @@ public async Task ShouldReuseExistingResource() Assert.Single(response.Volumes); } - [Fact] - public void ContainersWithDifferentNamesShouldHaveDifferentHashes() + public static class ReuseHash { - var hash1 = new ReuseHashContainerBuilder().WithName("Name1").GetReuseHash(); - var hash2 = new ReuseHashContainerBuilder().WithName("Name2").GetReuseHash(); - - Assert.NotEqual(hash1, hash2); + public sealed class NotEqual + { + [Fact] + public void ForDifferentNames() + { + var hash1 = new ReuseHashContainerBuilder().WithName("Name1").GetReuseHash(); + var hash2 = new ReuseHashContainerBuilder().WithName("Name2").GetReuseHash(); + Assert.NotEqual(hash1, hash2); + } + } } public static class UnsupportedBuilderConfigurationTest diff --git a/tests/Testcontainers.Platform.Linux.Tests/Testcontainers.Platform.Linux.Tests.csproj b/tests/Testcontainers.Platform.Linux.Tests/Testcontainers.Platform.Linux.Tests.csproj index 5cde0f59f..d7c3cd709 100644 --- a/tests/Testcontainers.Platform.Linux.Tests/Testcontainers.Platform.Linux.Tests.csproj +++ b/tests/Testcontainers.Platform.Linux.Tests/Testcontainers.Platform.Linux.Tests.csproj @@ -8,6 +8,7 @@ + diff --git a/tests/Testcontainers.Platform.Linux.Tests/Usings.cs b/tests/Testcontainers.Platform.Linux.Tests/Usings.cs index 7674d6b7e..ea641a068 100644 --- a/tests/Testcontainers.Platform.Linux.Tests/Usings.cs +++ b/tests/Testcontainers.Platform.Linux.Tests/Usings.cs @@ -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; \ No newline at end of file