Skip to content

Commit

Permalink
increase logging of SqlClientListenerTests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz committed Oct 19, 2023
1 parent 78893bb commit 3d2244b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
<ProjectReference Include="$(SolutionRoot)\test\Elastic.Apm.Tests.Utilities\Elastic.Apm.Tests.Utilities.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="..\..\xunit.runner.json" Link="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 3d2244b

Please sign in to comment.