Skip to content

Commit

Permalink
chore: Update Testcontainers for .NET to version 2.3.0 (#1953)
Browse files Browse the repository at this point in the history
* chore: Update Testcontainers for .NET to version 2.3.0

* fix(Elastic.Clients.Elasticsearch.Tests): TC for .NET does not always resolve the Hostname property to localhost (it varies accordingly to the Docker environment)

* fix(Elastic.Apm.Profiler.Managed.Tests): Set mandatory Passwort property

* fix: Remove private Docker registry

* fix(Elastic.Apm.Profiler.Managed.Tests): Remove OracleProviderExpectedSpans span count

Co-authored-by: Wolfgang Ziegler <[email protected]>
Co-authored-by: Gergely Kalapos <[email protected]>
  • Loading branch information
3 people authored Dec 28, 2022
1 parent 7d29a5e commit d7d185b
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 40 deletions.
9 changes: 4 additions & 5 deletions sample/StackExchangeRedisSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers.Builders;
using DotNet.Testcontainers.Containers.Configurations.Databases;
using DotNet.Testcontainers.Containers.Modules.Databases;
using System.Threading.Tasks;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;
using Elastic.Apm;
using Elastic.Apm.Api;
using Elastic.Apm.StackExchange.Redis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageReference Include="StackExchange.Redis" Version="2.0.495" />
<!-- Strong name any assemblies that aren't i.e. DotNet.Testcontainers -->
<PackageReference Include="StrongNamer" Version="0.2.5" />
<PackageReference Include="DotNet.Testcontainers" Version="1.4.0" />
<PackageReference Include="Testcontainers" Version="2.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.1.0" />
<PackageReference Include="Elasticsearch.Net.VirtualizedCluster" Version="7.6.1" />
<PackageReference Include="Testcontainers" Version="2.1.0" />
<PackageReference Include="Testcontainers" Version="2.3.0" />
<!-- Strong name any assemblies that aren't i.e. DotNet.Testcontainers -->
<PackageReference Include="StrongNamer" Version="0.2.5" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task InitializeAsync()

public async Task DisposeAsync()
{
if (_container.State == TestcontainersState.Running)
if (_container.State == TestcontainersStates.Running)
{
await _container.StopAsync();
await _container.DisposeAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="FluentAssertions" Version="5.6.0" />
<PackageReference Include="FluentAssertions.Analyzers" Version="0.11.4" />
<PackageReference Include="DotNet.Testcontainers" Version="1.4.0" />
<PackageReference Include="Testcontainers" Version="2.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using DotNet.Testcontainers.Containers.Configurations;
using DotNet.Testcontainers.Containers.Modules.Abstractions;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;
using Microsoft.Extensions.Logging;

namespace Elastic.Apm.MongoDb.Tests.Fixture
{
public sealed class MongoDbTestcontainer : TestcontainerDatabase
{
internal MongoDbTestcontainer(ITestcontainersConfiguration configuration)
: base(configuration)
internal MongoDbTestcontainer(ITestcontainersConfiguration configuration, ILogger logger)
: base(configuration, logger)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
// See the LICENSE file in the project root for more information

using System.IO;
using DotNet.Testcontainers.Containers.Configurations.Abstractions;
using DotNet.Testcontainers.Containers.OutputConsumers;
using DotNet.Testcontainers.Containers.WaitStrategies;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Configurations;

namespace Elastic.Apm.MongoDb.Tests.Fixture
{
Expand Down
2 changes: 1 addition & 1 deletion test/Elastic.Apm.MongoDb.Tests/Fixture/MongoFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using DotNet.Testcontainers.Containers.Builders;
using DotNet.Testcontainers.Builders;
using MongoDB.Driver;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class AdoNetTestData : IEnumerable<object[]>
public const int DbRunnerExpectedRunAllAsyncSpans = 111;
public const int DbRunnerExpectedRunBaseTypesAsyncSpans = 68;

// frequent commands are executed to retrieve session parameters. we should ignore these
public const int OracleProviderExpectedSpans = 63;
public const string OracleProviderSpanNameStart = "DECLARE";

public IEnumerator<object[]> GetEnumerator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task CaptureAutoInstrumentedSpans(string targetFramework)
}

apmServer.ReceivedData.Transactions.Should().HaveCount(2);
apmServer.ReceivedData.Spans.Should().HaveCount(AdoNetTestData.DbRunnerExpectedTotalSpans + AdoNetTestData.OracleProviderExpectedSpans);
apmServer.ReceivedData.Spans.Should().HaveCount(AdoNetTestData.DbRunnerExpectedTotalSpans);

var testSpans = apmServer.ReceivedData.Spans
.Where(s => !s.Name.StartsWith(AdoNetTestData.OracleProviderSpanNameStart))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task CaptureAutoInstrumentedSpans(string targetFramework)

apmServer.ReceivedData.Transactions.Should().HaveCount(2);

apmServer.ReceivedData.Spans.Should().HaveCount(AdoNetTestData.DbRunnerExpectedTotalSpans + AdoNetTestData.OracleProviderExpectedSpans);
apmServer.ReceivedData.Spans.Should().HaveCount(AdoNetTestData.DbRunnerExpectedTotalSpans);

var testSpans = apmServer.ReceivedData.Spans
.Where(s => !s.Name.StartsWith(AdoNetTestData.OracleProviderSpanNameStart))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class OracleSqlFixture : IAsyncLifetime
public OracleSqlFixture()
{
var builder = new TestcontainersBuilder<OracleTestcontainer>()
.WithDatabase(new OracleTestcontainerConfiguration());
.WithDatabase(new OracleTestcontainerConfiguration { Password = "oracle" });

_container = builder.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.19.120" />
<PackageReference Include="Proc" Version="0.6.2" />
<PackageReference Include="DotNet.Testcontainers" Version="1.6.0-beta.2020" />
<PackageReference Include="Testcontainers" Version="2.3.0" />
<PackageReference Include="StrongNamer" Version="0.2.5" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.1.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
<PackageReference Include="Testcontainers" Version="2.1.0" />
<PackageReference Include="Testcontainers" Version="2.3.0" />
<!-- Strong name any assemblies that aren't i.e. DotNet.Testcontainers -->
<PackageReference Include="StrongNamer" Version="0.2.5" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</PackageReference>
<PackageReference Include="StackExchange.Redis" Version="2.0.495" />
<PackageReference Include="Proc" Version="0.6.2" />
<PackageReference Include="DotNet.Testcontainers" Version="1.4.0" />
<PackageReference Include="Testcontainers" Version="2.3.0" />
<!-- Strong name any assemblies that aren't i.e. DotNet.Testcontainers -->
<PackageReference Include="StrongNamer" Version="0.2.5" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers.Builders;
using DotNet.Testcontainers.Containers.Configurations.Databases;
using DotNet.Testcontainers.Containers.Modules.Databases;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;
using Elastic.Apm.Api;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.1" />
<PackageReference Include="Testcontainers" Version="2.2.0" />
<PackageReference Include="Testcontainers" Version="2.3.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class ElasticsearchTestFixture : IAsyncDisposable, IAsyncLifetime

public ElasticsearchTestFixture() =>
Container = new TestcontainersBuilder<ElasticsearchTestcontainer>()
.WithImage("docker.elastic.co/elasticsearch/elasticsearch:8.5")
.WithDatabase(_configuration)
.Build();

Expand Down
20 changes: 10 additions & 10 deletions test/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ await apmAgent.Tracer.CaptureTransaction("Test", "Foo", async () =>
payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("db.system", "elasticsearch"));
payloadSender.FirstSpan.Otel.Attributes.Should()
.Contain(new KeyValuePair<string, string>("http.url",
$"https://localhost:{_esClientListenerFixture.Container.Port}/my-tweet-index/_doc/1"));
payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("net.peer.name", "localhost"));
$"{_esClientListenerFixture.Container.ConnectionString}/my-tweet-index/_doc/1"));
payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("net.peer.name", _esClientListenerFixture.Container.Hostname));
}


Expand All @@ -71,8 +71,8 @@ await apmAgent.Tracer.CaptureTransaction("Test", "Foo", async () =>
payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("db.system", "elasticsearch"));
payloadSender.FirstSpan.Otel.Attributes.Should()
.Contain(new KeyValuePair<string, string>("http.url",
$"https://localhost:{_esClientListenerFixture.Container.Port}/my-tweet-index/_doc/1"));
payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("net.peer.name", "localhost"));
$"{_esClientListenerFixture.Container.ConnectionString}/my-tweet-index/_doc/1"));
payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("net.peer.name", _esClientListenerFixture.Container.Hostname));
}

[DockerFact]
Expand All @@ -98,8 +98,8 @@ await apmAgent.Tracer.CaptureTransaction("Test", "Foo", async () =>
payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("db.system", "elasticsearch"));
payloadSender.FirstSpan.Otel.Attributes.Should()
.Contain(new KeyValuePair<string, string>("http.url",
$"https://localhost:{_esClientListenerFixture.Container.Port}/my-tweet-index/_search"));
payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("net.peer.name", "localhost"));
$"{_esClientListenerFixture.Container.ConnectionString}/my-tweet-index/_search"));
payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("net.peer.name", _esClientListenerFixture.Container.Hostname));
}

[DockerFact]
Expand Down Expand Up @@ -133,8 +133,8 @@ await apmAgent.Tracer.CaptureTransaction("Test", "Foo", async () =>
updateSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("db.system", "elasticsearch"));
updateSpan.Otel.Attributes.Should()
.Contain(new KeyValuePair<string, string>("http.url",
$"https://localhost:{_esClientListenerFixture.Container.Port}/my-tweet-index/_update/1"));
updateSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("net.peer.name", "localhost"));
$"{_esClientListenerFixture.Container.ConnectionString}/my-tweet-index/_update/1"));
updateSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("net.peer.name", _esClientListenerFixture.Container.Hostname));
}

[DockerFact]
Expand All @@ -161,8 +161,8 @@ await apmAgent.Tracer.CaptureTransaction("Test", "Foo", async () =>
payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("db.system", "elasticsearch"));
payloadSender.FirstSpan.Otel.Attributes.Should()
.Contain(new KeyValuePair<string, string>("http.url",
$"https://localhost:{_esClientListenerFixture.Container.Port}/my-tweet-index/_doc/1"));
payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("net.peer.name", "localhost"));
$"{_esClientListenerFixture.Container.ConnectionString}/my-tweet-index/_doc/1"));
payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair<string, string>("net.peer.name", _esClientListenerFixture.Container.Hostname));
}

private (MockPayloadSender, ApmAgent) SetUpAgent()
Expand Down

0 comments on commit d7d185b

Please sign in to comment.