Skip to content

Commit 59a8b4a

Browse files
committed
Dispose Testcontainers and update to V4
1 parent f9e8d09 commit 59a8b4a

7 files changed

Lines changed: 53 additions & 85 deletions

File tree

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AerospikeTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Collections.Generic;
88
using System.Linq;
99
using System.Threading.Tasks;
10+
using Datadog.Trace.ClrProfiler.IntegrationTests.Helpers;
1011
using Datadog.Trace.Configuration;
1112
using Datadog.Trace.TestHelpers;
1213
using Datadog.Trace.TestHelpers.AutoInstrumentation.Containers;
@@ -21,7 +22,8 @@ namespace Datadog.Trace.ClrProfiler.IntegrationTests
2122
[Trait("RequiresDockerDependency", "true")]
2223
[Trait("DockerGroup", "2")]
2324
[UsesVerify]
24-
public class AerospikeTests : TracingIntegrationTest, IClassFixture<AerospikeFixture>
25+
[Collection(AerospikeCollection.Name)]
26+
public class AerospikeTests : TracingIntegrationTest
2527
{
2628
public AerospikeTests(ITestOutputHelper output, AerospikeFixture aerospikeFixture)
2729
: base("Aerospike", output)

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Datadog.Trace.ClrProfiler.IntegrationTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
2929

30-
<PackageReference Include="Testcontainers" Version="3.6.0" />
30+
<PackageReference Include="Testcontainers" Version="4.11.0" />
3131
<PackageReference Include="StrongNamer" Version="0.2.5" />
3232
</ItemGroup>
3333

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// <copyright file="ContainersCollection.cs" company="Datadog">
2+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4+
// </copyright>
5+
#pragma warning disable SA1649 // File name should match first type name (this will just store all the classes)
6+
#pragma warning disable SA1402 // File may only contain a single type (this will just store all the classes)
7+
using Datadog.Trace.TestHelpers.AutoInstrumentation.Containers;
8+
using Xunit;
9+
10+
namespace Datadog.Trace.ClrProfiler.IntegrationTests.Helpers
11+
{
12+
[CollectionDefinition(Name)]
13+
14+
public class AerospikeCollection : ICollectionFixture<AerospikeFixture>
15+
{
16+
public const string Name = "Aerospike";
17+
}
18+
}
19+
20+
#pragma warning restore SA1649 // File name should match first type name
21+
#pragma warning restore SA1402 // File may only contain a single type

tracer/test/Datadog.Trace.TestHelpers.AutoInstrumentation/Containers/AerospikeFixture.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@ protected override async Task InitializeResources(Action<string, object> registe
3030
// pinning to a known good version because the latest version
3131
// (6.3.0.5 at time of issue) causes 'Server memory error' and flake
3232
// Keep syncronized image version with docker-compose.yml
33-
var container = new ContainerBuilder()
34-
.WithImage("aerospike/aerospike-server:6.2.0.6")
33+
var container = new ContainerBuilder("aerospike/aerospike-server:6.2.0.6")
3534
.WithPortBinding(AerospikePort, true)
3635
.WithCreateParameterModifier(p =>
37-
{
38-
p.HostConfig ??= new HostConfig();
39-
p.HostConfig.Ulimits = new List<Ulimit>
36+
{
37+
p.HostConfig ??= new HostConfig();
38+
p.HostConfig.Ulimits = new List<Ulimit>
4039
{
4140
// Aerospike requires a minimum of 15000 file descriptors, otherwise it'll fail to start
4241
// Some versions of dockerengine set a lower limit (1024)
4342
new Ulimit { Name = "nofile", Soft = 15000, Hard = 15000 }
4443
};
45-
})
46-
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(AerospikePort))
44+
})
45+
.WithWaitStrategy(Wait.ForUnixContainer().UntilInternalTcpPortIsAvailable(AerospikePort))
4746
.Build();
4847

4948
await container.StartAsync();

tracer/test/Datadog.Trace.TestHelpers.AutoInstrumentation/Containers/ContainerFixture.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,28 @@ public abstract class ContainerFixture : IAsyncLifetime
1919

2020
public async Task InitializeAsync()
2121
{
22-
_resources = await ContainersRegistry.GetOrAdd(GetType(), InitializeResources);
22+
_resources = await InitializeResources().ConfigureAwait(false);
2323
}
2424

25-
// Do not implement, the ContainersRegistry is responsible for disposing the containers
26-
public Task DisposeAsync() => Task.CompletedTask;
25+
public async Task DisposeAsync()
26+
{
27+
if (_resources is null)
28+
{
29+
return;
30+
}
31+
32+
foreach (var resource in _resources.Values)
33+
{
34+
if (resource is IAsyncDisposable asyncDisposable)
35+
{
36+
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
37+
}
38+
else if (resource is IDisposable disposable)
39+
{
40+
disposable.Dispose();
41+
}
42+
}
43+
}
2744

2845
public virtual IEnumerable<KeyValuePair<string, string>> GetEnvironmentVariables() => Enumerable.Empty<KeyValuePair<string, string>>();
2946

tracer/test/Datadog.Trace.TestHelpers.AutoInstrumentation/Containers/ContainersRegistry.cs

Lines changed: 0 additions & 72 deletions
This file was deleted.

tracer/test/Datadog.Trace.TestHelpers.AutoInstrumentation/Datadog.Trace.TestHelpers.AutoInstrumentation.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<ItemGroup>
4+
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
45
<PackageReference Include="SharpPdb" Version="1.0.4" />
5-
<PackageReference Include="Testcontainers" Version="3.6.0" />
6+
<PackageReference Include="Testcontainers" Version="4.11.0" />
67
</ItemGroup>
78

89
<ItemGroup>

0 commit comments

Comments
 (0)