From d7d185bf6eb7a4e6b35e478fe9bf44ef1b1acf60 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Wed, 28 Dec 2022 14:56:41 +0100 Subject: [PATCH] chore: Update Testcontainers for .NET to version 2.3.0 (#1953) * 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 Co-authored-by: Gergely Kalapos --- sample/StackExchangeRedisSample/Program.cs | 9 ++++----- .../StackExchangeRedisSample.csproj | 2 +- .../Elastic.Apm.Elasticsearch.Tests.csproj | 2 +- .../ElasticsearchFixture.cs | 2 +- .../Elastic.Apm.MongoDb.Tests.csproj | 2 +- .../Fixture/MongoDbTestcontainer.cs | 9 +++++---- .../MongoDbTestcontainerConfiguration.cs | 5 ++--- .../Fixture/MongoFixture.cs | 2 +- .../AdoNet/AdoNetTestData.cs | 2 -- .../OracleManagedDataAccessCommandTests.cs | 2 +- ...OracleManagedDataAccessCoreCommandTests.cs | 2 +- .../AdoNet/OracleSqlFixture.cs | 2 +- .../Elastic.Apm.Profiler.Managed.Tests.csproj | 2 +- .../Elastic.Apm.SqlClient.Tests.csproj | 2 +- ...astic.Apm.StackExchange.Redis.Tests.csproj | 2 +- .../ProfilingSessionTests.cs | 6 +++--- ...Elastic.Clients.Elasticsearch.Tests.csproj | 2 +- .../ElasticsearchTestFixture.cs | 1 - .../ElasticsearchTests.cs | 20 +++++++++---------- 19 files changed, 36 insertions(+), 40 deletions(-) diff --git a/sample/StackExchangeRedisSample/Program.cs b/sample/StackExchangeRedisSample/Program.cs index 3406b2e0a..b96cb3db0 100644 --- a/sample/StackExchangeRedisSample/Program.cs +++ b/sample/StackExchangeRedisSample/Program.cs @@ -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; diff --git a/sample/StackExchangeRedisSample/StackExchangeRedisSample.csproj b/sample/StackExchangeRedisSample/StackExchangeRedisSample.csproj index 6ad5af185..cae558447 100644 --- a/sample/StackExchangeRedisSample/StackExchangeRedisSample.csproj +++ b/sample/StackExchangeRedisSample/StackExchangeRedisSample.csproj @@ -9,7 +9,7 @@ - + diff --git a/test/Elastic.Apm.Elasticsearch.Tests/Elastic.Apm.Elasticsearch.Tests.csproj b/test/Elastic.Apm.Elasticsearch.Tests/Elastic.Apm.Elasticsearch.Tests.csproj index 99d1b57de..13e8d4ff6 100644 --- a/test/Elastic.Apm.Elasticsearch.Tests/Elastic.Apm.Elasticsearch.Tests.csproj +++ b/test/Elastic.Apm.Elasticsearch.Tests/Elastic.Apm.Elasticsearch.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/test/Elastic.Apm.Elasticsearch.Tests/ElasticsearchFixture.cs b/test/Elastic.Apm.Elasticsearch.Tests/ElasticsearchFixture.cs index ca15a17ba..bf3c72758 100644 --- a/test/Elastic.Apm.Elasticsearch.Tests/ElasticsearchFixture.cs +++ b/test/Elastic.Apm.Elasticsearch.Tests/ElasticsearchFixture.cs @@ -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(); diff --git a/test/Elastic.Apm.MongoDb.Tests/Elastic.Apm.MongoDb.Tests.csproj b/test/Elastic.Apm.MongoDb.Tests/Elastic.Apm.MongoDb.Tests.csproj index aebd7a350..46dbf3b9d 100644 --- a/test/Elastic.Apm.MongoDb.Tests/Elastic.Apm.MongoDb.Tests.csproj +++ b/test/Elastic.Apm.MongoDb.Tests/Elastic.Apm.MongoDb.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/test/Elastic.Apm.MongoDb.Tests/Fixture/MongoDbTestcontainer.cs b/test/Elastic.Apm.MongoDb.Tests/Fixture/MongoDbTestcontainer.cs index ed6c3a53c..1b7b1130c 100644 --- a/test/Elastic.Apm.MongoDb.Tests/Fixture/MongoDbTestcontainer.cs +++ b/test/Elastic.Apm.MongoDb.Tests/Fixture/MongoDbTestcontainer.cs @@ -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) { } diff --git a/test/Elastic.Apm.MongoDb.Tests/Fixture/MongoDbTestcontainerConfiguration.cs b/test/Elastic.Apm.MongoDb.Tests/Fixture/MongoDbTestcontainerConfiguration.cs index 2953b2018..fe881b482 100644 --- a/test/Elastic.Apm.MongoDb.Tests/Fixture/MongoDbTestcontainerConfiguration.cs +++ b/test/Elastic.Apm.MongoDb.Tests/Fixture/MongoDbTestcontainerConfiguration.cs @@ -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 { diff --git a/test/Elastic.Apm.MongoDb.Tests/Fixture/MongoFixture.cs b/test/Elastic.Apm.MongoDb.Tests/Fixture/MongoFixture.cs index 408b8ef08..77045f799 100644 --- a/test/Elastic.Apm.MongoDb.Tests/Fixture/MongoFixture.cs +++ b/test/Elastic.Apm.MongoDb.Tests/Fixture/MongoFixture.cs @@ -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; diff --git a/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/AdoNetTestData.cs b/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/AdoNetTestData.cs index 8b878b8bd..6d835db5f 100644 --- a/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/AdoNetTestData.cs +++ b/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/AdoNetTestData.cs @@ -16,8 +16,6 @@ public class AdoNetTestData : IEnumerable 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 GetEnumerator() diff --git a/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleManagedDataAccessCommandTests.cs b/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleManagedDataAccessCommandTests.cs index a00eb7c4f..f8ccfa5b6 100644 --- a/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleManagedDataAccessCommandTests.cs +++ b/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleManagedDataAccessCommandTests.cs @@ -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)) diff --git a/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleManagedDataAccessCoreCommandTests.cs b/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleManagedDataAccessCoreCommandTests.cs index c19e056d6..e70fa619f 100644 --- a/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleManagedDataAccessCoreCommandTests.cs +++ b/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleManagedDataAccessCoreCommandTests.cs @@ -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)) diff --git a/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleSqlFixture.cs b/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleSqlFixture.cs index 1d014808d..fa9938e90 100644 --- a/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleSqlFixture.cs +++ b/test/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleSqlFixture.cs @@ -23,7 +23,7 @@ public class OracleSqlFixture : IAsyncLifetime public OracleSqlFixture() { var builder = new TestcontainersBuilder() - .WithDatabase(new OracleTestcontainerConfiguration()); + .WithDatabase(new OracleTestcontainerConfiguration { Password = "oracle" }); _container = builder.Build(); } diff --git a/test/Elastic.Apm.Profiler.Managed.Tests/Elastic.Apm.Profiler.Managed.Tests.csproj b/test/Elastic.Apm.Profiler.Managed.Tests/Elastic.Apm.Profiler.Managed.Tests.csproj index c2a5930e4..bf83a1bf6 100644 --- a/test/Elastic.Apm.Profiler.Managed.Tests/Elastic.Apm.Profiler.Managed.Tests.csproj +++ b/test/Elastic.Apm.Profiler.Managed.Tests/Elastic.Apm.Profiler.Managed.Tests.csproj @@ -13,7 +13,7 @@ - + diff --git a/test/Elastic.Apm.SqlClient.Tests/Elastic.Apm.SqlClient.Tests.csproj b/test/Elastic.Apm.SqlClient.Tests/Elastic.Apm.SqlClient.Tests.csproj index f4e604277..a61ab25fc 100644 --- a/test/Elastic.Apm.SqlClient.Tests/Elastic.Apm.SqlClient.Tests.csproj +++ b/test/Elastic.Apm.SqlClient.Tests/Elastic.Apm.SqlClient.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/test/Elastic.Apm.StackExchange.Redis.Tests/Elastic.Apm.StackExchange.Redis.Tests.csproj b/test/Elastic.Apm.StackExchange.Redis.Tests/Elastic.Apm.StackExchange.Redis.Tests.csproj index 9dbaf85ef..6b5845fff 100644 --- a/test/Elastic.Apm.StackExchange.Redis.Tests/Elastic.Apm.StackExchange.Redis.Tests.csproj +++ b/test/Elastic.Apm.StackExchange.Redis.Tests/Elastic.Apm.StackExchange.Redis.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/test/Elastic.Apm.StackExchange.Redis.Tests/ProfilingSessionTests.cs b/test/Elastic.Apm.StackExchange.Redis.Tests/ProfilingSessionTests.cs index 986dea489..eac4361f1 100644 --- a/test/Elastic.Apm.StackExchange.Redis.Tests/ProfilingSessionTests.cs +++ b/test/Elastic.Apm.StackExchange.Redis.Tests/ProfilingSessionTests.cs @@ -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; diff --git a/test/Elastic.Clients.Elasticsearch.Tests/Elastic.Clients.Elasticsearch.Tests.csproj b/test/Elastic.Clients.Elasticsearch.Tests/Elastic.Clients.Elasticsearch.Tests.csproj index 04a56259e..b93bf466b 100644 --- a/test/Elastic.Clients.Elasticsearch.Tests/Elastic.Clients.Elasticsearch.Tests.csproj +++ b/test/Elastic.Clients.Elasticsearch.Tests/Elastic.Clients.Elasticsearch.Tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/test/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTestFixture.cs b/test/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTestFixture.cs index b6d37c2b4..17598d4af 100644 --- a/test/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTestFixture.cs +++ b/test/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTestFixture.cs @@ -20,7 +20,6 @@ public class ElasticsearchTestFixture : IAsyncDisposable, IAsyncLifetime public ElasticsearchTestFixture() => Container = new TestcontainersBuilder() - .WithImage("docker.elastic.co/elasticsearch/elasticsearch:8.5") .WithDatabase(_configuration) .Build(); diff --git a/test/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs b/test/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs index 360a11899..668ed51c5 100644 --- a/test/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs +++ b/test/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs @@ -43,8 +43,8 @@ await apmAgent.Tracer.CaptureTransaction("Test", "Foo", async () => payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair("db.system", "elasticsearch")); payloadSender.FirstSpan.Otel.Attributes.Should() .Contain(new KeyValuePair("http.url", - $"https://localhost:{_esClientListenerFixture.Container.Port}/my-tweet-index/_doc/1")); - payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", "localhost")); + $"{_esClientListenerFixture.Container.ConnectionString}/my-tweet-index/_doc/1")); + payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", _esClientListenerFixture.Container.Hostname)); } @@ -71,8 +71,8 @@ await apmAgent.Tracer.CaptureTransaction("Test", "Foo", async () => payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair("db.system", "elasticsearch")); payloadSender.FirstSpan.Otel.Attributes.Should() .Contain(new KeyValuePair("http.url", - $"https://localhost:{_esClientListenerFixture.Container.Port}/my-tweet-index/_doc/1")); - payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", "localhost")); + $"{_esClientListenerFixture.Container.ConnectionString}/my-tweet-index/_doc/1")); + payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", _esClientListenerFixture.Container.Hostname)); } [DockerFact] @@ -98,8 +98,8 @@ await apmAgent.Tracer.CaptureTransaction("Test", "Foo", async () => payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair("db.system", "elasticsearch")); payloadSender.FirstSpan.Otel.Attributes.Should() .Contain(new KeyValuePair("http.url", - $"https://localhost:{_esClientListenerFixture.Container.Port}/my-tweet-index/_search")); - payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", "localhost")); + $"{_esClientListenerFixture.Container.ConnectionString}/my-tweet-index/_search")); + payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", _esClientListenerFixture.Container.Hostname)); } [DockerFact] @@ -133,8 +133,8 @@ await apmAgent.Tracer.CaptureTransaction("Test", "Foo", async () => updateSpan.Otel.Attributes.Should().Contain(new KeyValuePair("db.system", "elasticsearch")); updateSpan.Otel.Attributes.Should() .Contain(new KeyValuePair("http.url", - $"https://localhost:{_esClientListenerFixture.Container.Port}/my-tweet-index/_update/1")); - updateSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", "localhost")); + $"{_esClientListenerFixture.Container.ConnectionString}/my-tweet-index/_update/1")); + updateSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", _esClientListenerFixture.Container.Hostname)); } [DockerFact] @@ -161,8 +161,8 @@ await apmAgent.Tracer.CaptureTransaction("Test", "Foo", async () => payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair("db.system", "elasticsearch")); payloadSender.FirstSpan.Otel.Attributes.Should() .Contain(new KeyValuePair("http.url", - $"https://localhost:{_esClientListenerFixture.Container.Port}/my-tweet-index/_doc/1")); - payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", "localhost")); + $"{_esClientListenerFixture.Container.ConnectionString}/my-tweet-index/_doc/1")); + payloadSender.FirstSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", _esClientListenerFixture.Container.Hostname)); } private (MockPayloadSender, ApmAgent) SetUpAgent()