From 55b9de62cc1a26beea4a1944315a765e64689db6 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 25 Jul 2023 10:44:45 +0200 Subject: [PATCH 1/6] Reenable profiler tests on windows --- .github/workflows/test-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index 2803094d9..f5c069d09 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -67,7 +67,7 @@ jobs: profiler-tests: runs-on: windows-2022 # Disable profiler tests for now - if: ${{ false }} + # if: ${{ false }} steps: - uses: actions/checkout@v3 - name: Bootstrap Action Workspace From 3c95ea02915d4b12cf93a4de46169231928df35a Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Thu, 27 Jul 2023 11:13:02 +0200 Subject: [PATCH 2/6] reenable other docker tests that were previously disabled on windows --- .../Docker/DockerFactAttribute.cs | 6 -- .../Docker/DockerTheoryAttribute.cs | 6 -- .../XUnit/DisabledOnWindowsFact.cs | 60 ------------------- .../XUnit/DisabledOnWindowsTheory.cs | 17 ++++++ .../ElasticsearchTests.cs | 5 +- .../MongoApmTests.cs | 5 +- .../EfCoreWithMsSqlTests.cs | 3 +- .../SqlClientListenerTests.cs | 7 ++- .../ProfilingSessionTests.cs | 7 ++- .../ElasticsearchTests.cs | 11 ++-- 10 files changed, 39 insertions(+), 88 deletions(-) delete mode 100644 test/Elastic.Apm.Tests.Utilities/XUnit/DisabledOnWindowsFact.cs create mode 100644 test/Elastic.Apm.Tests.Utilities/XUnit/DisabledOnWindowsTheory.cs diff --git a/test/Elastic.Apm.Tests.Utilities/Docker/DockerFactAttribute.cs b/test/Elastic.Apm.Tests.Utilities/Docker/DockerFactAttribute.cs index 4058c6168..910305267 100644 --- a/test/Elastic.Apm.Tests.Utilities/Docker/DockerFactAttribute.cs +++ b/test/Elastic.Apm.Tests.Utilities/Docker/DockerFactAttribute.cs @@ -20,12 +20,6 @@ static DockerFactAttribute() { try { - if (TestEnvironment.IsCi && TestEnvironment.IsWindows) - { - _skip = "not running tests that require docker in CI on Windows"; - return; - } - var result = Proc.Start(new StartArguments("docker", "--version")); if (result.ExitCode != 0) _skip = "docker not installed"; diff --git a/test/Elastic.Apm.Tests.Utilities/Docker/DockerTheoryAttribute.cs b/test/Elastic.Apm.Tests.Utilities/Docker/DockerTheoryAttribute.cs index 3e4395a96..b94e8c31e 100644 --- a/test/Elastic.Apm.Tests.Utilities/Docker/DockerTheoryAttribute.cs +++ b/test/Elastic.Apm.Tests.Utilities/Docker/DockerTheoryAttribute.cs @@ -20,12 +20,6 @@ static DockerTheoryAttribute() { try { - if (TestEnvironment.IsCi && TestEnvironment.IsWindows) - { - _skip = "not running tests that require docker in CI on Windows"; - return; - } - var result = Proc.Start(new StartArguments("docker", "--version")); if (result.ExitCode != 0) _skip = "docker not installed"; diff --git a/test/Elastic.Apm.Tests.Utilities/XUnit/DisabledOnWindowsFact.cs b/test/Elastic.Apm.Tests.Utilities/XUnit/DisabledOnWindowsFact.cs deleted file mode 100644 index 315edd040..000000000 --- a/test/Elastic.Apm.Tests.Utilities/XUnit/DisabledOnWindowsFact.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Licensed to Elasticsearch B.V under -// one or more agreements. -// 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 Elastic.Apm.Tests.Utilities.Docker; -using Xunit; - -namespace Elastic.Apm.Tests.Utilities.XUnit; - -public sealed class DisabledOnWindowsFact : FactAttribute -{ - public DisabledOnWindowsFact() - { - if (TestEnvironment.IsWindows) - Skip = "This test is disabled on Windows."; - } -} - -public sealed class DisabledOnFullFrameworkFact : FactAttribute -{ - public DisabledOnFullFrameworkFact() - { -#if NETFRAMEWORK - Skip = "This test is disabled on .NET Full Framework"; -#endif - } -} - -/// -/// May be applied to tests which depend on Linux Docker images which will not be -/// available when running on Windows images from GitHub actions. -/// -public sealed class DisabledOnWindowsGitHubActionsDockerFact : DockerFactAttribute -{ - public DisabledOnWindowsGitHubActionsDockerFact() - { - if (TestEnvironment.IsGitHubActions && TestEnvironment.IsWindows) - Skip = "This test is disabled on Windows when running under GitHub Actions."; - } -} - -public sealed class DisabledOnWindowsTheory : TheoryAttribute -{ - public DisabledOnWindowsTheory() - { - if (TestEnvironment.IsWindows) - Skip = "This test is disabled on Windows."; - } -} - -public sealed class DisabledOnFullFrameworkTheory : TheoryAttribute -{ - public DisabledOnFullFrameworkTheory() - { -#if NETFRAMEWORK - Skip = "This test is disabled on .NET Full Framework"; -#endif - } -} diff --git a/test/Elastic.Apm.Tests.Utilities/XUnit/DisabledOnWindowsTheory.cs b/test/Elastic.Apm.Tests.Utilities/XUnit/DisabledOnWindowsTheory.cs new file mode 100644 index 000000000..1217f926d --- /dev/null +++ b/test/Elastic.Apm.Tests.Utilities/XUnit/DisabledOnWindowsTheory.cs @@ -0,0 +1,17 @@ +// Licensed to Elasticsearch B.V under +// one or more agreements. +// 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 Xunit; + +namespace Elastic.Apm.Tests.Utilities.XUnit; + +public sealed class DisabledOnWindowsTheory : TheoryAttribute +{ + public DisabledOnWindowsTheory() + { + if (TestEnvironment.IsWindows) + Skip = "This test is disabled on Windows."; + } +} diff --git a/test/instrumentations/Elastic.Apm.Elasticsearch.Tests/ElasticsearchTests.cs b/test/instrumentations/Elastic.Apm.Elasticsearch.Tests/ElasticsearchTests.cs index a02cc7285..31faf115c 100644 --- a/test/instrumentations/Elastic.Apm.Elasticsearch.Tests/ElasticsearchTests.cs +++ b/test/instrumentations/Elastic.Apm.Elasticsearch.Tests/ElasticsearchTests.cs @@ -9,6 +9,7 @@ using Elastic.Apm.Api; using Elastic.Apm.DiagnosticSource; using Elastic.Apm.Tests.Utilities; +using Elastic.Apm.Tests.Utilities.Docker; using Elastic.Apm.Tests.Utilities.XUnit; using Elasticsearch.Net; using FluentAssertions; @@ -28,7 +29,7 @@ public ElasticsearchTests(ElasticsearchFixture fixture) _client = new ElasticLowLevelClient(settings); } - [DisabledOnWindowsGitHubActionsDockerFact] + [DockerFact] public async Task Elasticsearch_Span_Should_Align_With_Spec() { var payloadSender = new MockPayloadSender(); @@ -86,7 +87,7 @@ private static void AssertSpan(ISpan span) span.Context.Destination.Port.Should().BeGreaterThan(0).And.BeLessThan(65536); } - [DisabledOnWindowsGitHubActionsDockerFact] + [DockerFact] public async Task Elasticsearch_Span_Does_Not_Have_Http_Child_Span() { var payloadSender = new MockPayloadSender(); diff --git a/test/instrumentations/Elastic.Apm.MongoDb.Tests/MongoApmTests.cs b/test/instrumentations/Elastic.Apm.MongoDb.Tests/MongoApmTests.cs index b843ef8d8..5313d1ad1 100644 --- a/test/instrumentations/Elastic.Apm.MongoDb.Tests/MongoApmTests.cs +++ b/test/instrumentations/Elastic.Apm.MongoDb.Tests/MongoApmTests.cs @@ -10,6 +10,7 @@ using Elastic.Apm.Api; using Elastic.Apm.MongoDb.Tests.Fixture; using Elastic.Apm.Tests.Utilities; +using Elastic.Apm.Tests.Utilities.Docker; using Elastic.Apm.Tests.Utilities.XUnit; using FluentAssertions; using MongoDB.Bson; @@ -64,7 +65,7 @@ public Task DisposeAsync(IMongoCollection collection) => private readonly MockPayloadSender _payloadSender; - [DisabledOnWindowsFact] + [DockerFact] public async Task ApmAgent_ShouldCorrectlyCaptureSpan() { // Arrange @@ -101,7 +102,7 @@ public async Task ApmAgent_ShouldCorrectlyCaptureSpan() }); } - [DisabledOnWindowsFact] + [DockerFact] public async Task ApmAgent_ShouldCorrectlyCaptureSpanAndError_WhenMongoCommandFailed() { // Arrange diff --git a/test/instrumentations/Elastic.Apm.SqlClient.Tests/EfCoreWithMsSqlTests.cs b/test/instrumentations/Elastic.Apm.SqlClient.Tests/EfCoreWithMsSqlTests.cs index b9977b98e..7c1cccbb1 100644 --- a/test/instrumentations/Elastic.Apm.SqlClient.Tests/EfCoreWithMsSqlTests.cs +++ b/test/instrumentations/Elastic.Apm.SqlClient.Tests/EfCoreWithMsSqlTests.cs @@ -8,6 +8,7 @@ using Elastic.Apm.EntityFrameworkCore; using Elastic.Apm.Instrumentations.SqlClient; using Elastic.Apm.Tests.Utilities; +using Elastic.Apm.Tests.Utilities.Docker; using Elastic.Apm.Tests.Utilities.XUnit; using FluentAssertions; using Microsoft.EntityFrameworkCore; @@ -43,7 +44,7 @@ public EfCoreWithMsSqlTests(ITestOutputHelper testOutputHelper, SqlServerFixture /// Executes a db query within a transaction while both SqlClient and EFCore capturing is active. /// Makes sure that the db call is only captured once - so only 1 of them captures the call, the other one ignores it. /// - [DisabledOnWindowsFact] + [DockerFact] public void BothEfCoreAndSqlClientCapturingActive() { var dbContextOptionsBuilder = new DbContextOptionsBuilder(); diff --git a/test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlClientListenerTests.cs b/test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlClientListenerTests.cs index 785cb6fd1..04268712a 100644 --- a/test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlClientListenerTests.cs +++ b/test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlClientListenerTests.cs @@ -11,6 +11,7 @@ using Elastic.Apm.Api; using Elastic.Apm.Instrumentations.SqlClient; using Elastic.Apm.Tests.Utilities; +using Elastic.Apm.Tests.Utilities.Docker; using Elastic.Apm.Tests.Utilities.XUnit; using FluentAssertions; using Xunit; @@ -63,7 +64,7 @@ public static IEnumerable Connections } } - [DisabledOnWindowsTheory] + [DockerTheory] [MemberData(nameof(Connections))] public async Task SqlClientDiagnosticListener_ShouldCaptureSpan(string providerName, Func connectionCreator) { @@ -117,7 +118,7 @@ await _apmAgent.Tracer.CaptureTransaction("transaction", "type", async _ => span.Context.Service.Target.Name.Should().Be(span.Context.Db.Instance); } - [DisabledOnWindowsTheory] + [DockerTheory] [MemberData(nameof(Connections))] public async Task SqlClientDiagnosticListener_ShouldCaptureErrorFromSystemSqlClient(string providerName, Func connectionCreator @@ -181,7 +182,7 @@ await _apmAgent.Tracer.CaptureTransaction("transaction", "type", async _ => span.Context.Service.Target.Name.Should().Be(span.Context.Db.Instance); } - [DisabledOnWindowsTheory] + [DockerTheory] [MemberData(nameof(Connections))] public async Task SqlClientDiagnosticListener_ShouldNotUseCumulativeDurations(string providerName, Func connectionCreator) { diff --git a/test/instrumentations/Elastic.Apm.StackExchange.Redis.Tests/ProfilingSessionTests.cs b/test/instrumentations/Elastic.Apm.StackExchange.Redis.Tests/ProfilingSessionTests.cs index 32f48532c..639456cca 100644 --- a/test/instrumentations/Elastic.Apm.StackExchange.Redis.Tests/ProfilingSessionTests.cs +++ b/test/instrumentations/Elastic.Apm.StackExchange.Redis.Tests/ProfilingSessionTests.cs @@ -8,16 +8,17 @@ using System.Threading.Tasks; using Elastic.Apm.Api; using Elastic.Apm.Tests.Utilities; -using Elastic.Apm.Tests.Utilities.XUnit; +using Elastic.Apm.Tests.Utilities.Docker; using FluentAssertions; using StackExchange.Redis; using Testcontainers.Redis; +using Xunit; namespace Elastic.Apm.StackExchange.Redis.Tests { public class ProfilingSessionTests { - [DisabledOnWindowsGitHubActionsDockerFact] + [DockerFact] public async Task Capture_Redis_Commands_On_Transaction() { await using var container = new RedisBuilder().Build(); @@ -75,7 +76,7 @@ await agent.Tracer.CaptureTransaction("Set and Get String", ApiConstants.TypeDb, await container.StopAsync(); } - [DisabledOnWindowsGitHubActionsDockerFact] + [DockerFact] public async Task Capture_Redis_Commands_On_Span() { await using var container = new RedisBuilder().Build(); diff --git a/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs b/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs index 59b1d0927..afda0ead1 100644 --- a/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs +++ b/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs @@ -32,7 +32,7 @@ public ElasticsearchTests(ITestOutputHelper testOutputHelper, ElasticsearchTestF _client = _esClientListenerFixture.Client ?? throw new Exception("ElasticsearchClient is `null`"); } - [DisabledOnWindowsGitHubActionsDockerFact] + [DockerFact] public async Task IndexDataTest() { var (payloadSender, apmAgent) = SetUpAgent(); @@ -56,7 +56,8 @@ public async Task IndexDataTest() elasticsearchSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", _esClientListenerFixture.Container.Hostname)); } - [DisabledOnWindowsGitHubActionsDockerFact] + + [DockerFact] public async Task GetDocumentTest() { // make sure data is present @@ -83,7 +84,7 @@ public async Task GetDocumentTest() elasticsearchSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", _esClientListenerFixture.Container.Hostname)); } - [DisabledOnWindowsGitHubActionsDockerFact] + [DockerFact] public async Task SearchDocumentTest() { // make sure data is present @@ -110,7 +111,7 @@ public async Task SearchDocumentTest() elasticsearchSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", _esClientListenerFixture.Container.Hostname)); } - [DisabledOnWindowsGitHubActionsDockerFact] + [DockerFact] public async Task UpdateDocumentTest() { // make sure data is present @@ -147,7 +148,7 @@ await apmAgent.Tracer.CaptureTransaction("Test", "Foo", async () => elasticsearchSpan.Otel.Attributes.Should().Contain(new KeyValuePair("net.peer.name", _esClientListenerFixture.Container.Hostname)); } - [DisabledOnWindowsGitHubActionsDockerFact] + [DockerFact] public async Task DeleteDocumentTest() { // make sure data is present From 669c6ac304337854c4554df38e836662086b82ef Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Fri, 22 Sep 2023 16:10:58 +0200 Subject: [PATCH 3/6] ci: try to setup testcontainers cloud Signed-off-by: Adrien Mannocci --- .github/workflows/test-windows.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index f5c069d09..a8734687f 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -78,6 +78,11 @@ jobs: - name: Build profiler run: ./build.bat profiler-zip + - name: Setup Testcontainers Cloud Client + uses: atomicjar/testcontainers-cloud-setup-action@v1 + with: + token: ${{ secrets.TC_CLOUD_TOKEN }} + - name: 'Tests: Profiler' uses: ./.github/workflows/test with: From 73165f7023376a61bd43bafa45cb230696173c9b Mon Sep 17 00:00:00 2001 From: Adrien Mannocci Date: Fri, 22 Sep 2023 16:36:46 +0200 Subject: [PATCH 4/6] fix: use correct import for docker facts Signed-off-by: Adrien Mannocci --- .../Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs b/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs index afda0ead1..39b0a76e6 100644 --- a/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs +++ b/test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs @@ -11,7 +11,7 @@ using Elastic.Apm.DiagnosticSource; using Elastic.Apm.Elasticsearch; using Elastic.Apm.Tests.Utilities; -using Elastic.Apm.Tests.Utilities.XUnit; +using Elastic.Apm.Tests.Utilities.Docker; using FluentAssertions; using Xunit; using Xunit.Abstractions; From 7a84757375d0e2671fbeda2df3208d86171ed059 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 10 Oct 2023 13:47:16 +0200 Subject: [PATCH 5/6] ensure test container cloud is setup for regular tests run too --- .github/workflows/test-windows.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index a8734687f..98dae98ad 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -40,6 +40,11 @@ jobs: - name: Build run: dotnet build -c Release --verbosity minimal + - name: Setup Testcontainers Cloud Client + uses: atomicjar/testcontainers-cloud-setup-action@v1 + with: + token: ${{ secrets.TC_CLOUD_TOKEN }} + - name: 'Tests: Unit' uses: ./.github/workflows/test with: @@ -57,7 +62,7 @@ jobs: - name: Build agent-zip run: ./build.bat agent-zip - + - name: 'Tests: StartupHooks' uses: ./.github/workflows/test with: From 24fe6aab24b244c962ecfcefc620bbcd838b7a4e Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Thu, 19 Oct 2023 13:58:33 +0200 Subject: [PATCH 6/6] increase logging of SqlClientListenerTests --- .../Elastic.Apm.SqlClient.Tests.csproj | 4 ++++ .../SqlClientListenerTests.cs | 5 ++-- .../SqlServerFixture.cs | 23 ++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/test/instrumentations/Elastic.Apm.SqlClient.Tests/Elastic.Apm.SqlClient.Tests.csproj b/test/instrumentations/Elastic.Apm.SqlClient.Tests/Elastic.Apm.SqlClient.Tests.csproj index 0f99a966f..b4906f29d 100644 --- a/test/instrumentations/Elastic.Apm.SqlClient.Tests/Elastic.Apm.SqlClient.Tests.csproj +++ b/test/instrumentations/Elastic.Apm.SqlClient.Tests/Elastic.Apm.SqlClient.Tests.csproj @@ -22,4 +22,8 @@ + + + + diff --git a/test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlClientListenerTests.cs b/test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlClientListenerTests.cs index 04268712a..d43650a79 100644 --- a/test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlClientListenerTests.cs +++ b/test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlClientListenerTests.cs @@ -39,9 +39,10 @@ public SqlClientListenerTests(ITestOutputHelper testOutputHelper, SqlServerFixtu _testOutputHelper = testOutputHelper; - _payloadSender = new MockPayloadSender(); + var logger = new LineWriterToLoggerAdaptor(new XunitOutputToLineWriterAdaptor(_testOutputHelper)); + _payloadSender = new MockPayloadSender(logger); _apmAgent = new ApmAgent(new TestAgentComponents( - new LineWriterToLoggerAdaptor(new XunitOutputToLineWriterAdaptor(_testOutputHelper)), + logger, payloadSender: _payloadSender)); _subscription = _apmAgent.Subscribe(new SqlClientDiagnosticSubscriber()); } diff --git a/test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlServerFixture.cs b/test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlServerFixture.cs index ea8eb88f9..2095543c0 100644 --- a/test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlServerFixture.cs +++ b/test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlServerFixture.cs @@ -6,18 +6,35 @@ using System.Threading.Tasks; using Testcontainers.MsSql; using Xunit; +using Xunit.Abstractions; +using Xunit.Sdk; namespace Elastic.Apm.SqlClient.Tests { // ReSharper disable once ClassNeverInstantiated.Global - it's used as a generic parameter public sealed class SqlServerFixture : IAsyncLifetime { - private readonly MsSqlContainer _container = new MsSqlBuilder().Build(); + private readonly MsSqlContainer _container; + private readonly IMessageSink _sink; public string ConnectionString => _container.GetConnectionString(); - public Task InitializeAsync() => _container.StartAsync(); + public SqlServerFixture(IMessageSink sink) + { + _sink = sink; + _container = new MsSqlBuilder() + .Build(); + } - public Task DisposeAsync() => _container.DisposeAsync().AsTask(); + public async Task InitializeAsync() + { + await _container.StartAsync(); + var (stdOut, stdErr) = await _container.GetLogsAsync(); + + _sink.OnMessage(new DiagnosticMessage(stdOut)); + _sink.OnMessage(new DiagnosticMessage(stdErr)); + } + + public async Task DisposeAsync() => await _container.DisposeAsync(); } }