Skip to content

Commit 69a3c5c

Browse files
committed
ensure we log startup in case of failed tests
1 parent 88b7f63 commit 69a3c5c

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<PackageVersion Include="Elastic.Aspire.Hosting.Elasticsearch" Version="9.3.0" />
2626
<PackageVersion Include="FakeItEasy" Version="8.3.0" />
2727
<PackageVersion Include="Elastic.Ingest.Elasticsearch" Version="0.11.3" />
28+
<PackageVersion Include="InMemoryLogger" Version="1.0.66" />
2829
<PackageVersion Include="MartinCostello.Logging.XUnit.v3" Version="0.6.0" />
2930
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.4" />
3031
<PackageVersion Include="Microsoft.OpenApi" Version="2.0.0-preview9" />
@@ -92,4 +93,4 @@
9293
</PackageVersion>
9394
<PackageVersion Include="xunit.v3" Version="2.0.2" />
9495
</ItemGroup>
95-
</Project>
96+
</Project>

tests-integration/Elastic.Assembler.IntegrationTests/AssembleFixture.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Aspire.Hosting.Testing;
77
using Elastic.Documentation.ServiceDefaults;
88
using FluentAssertions;
9+
using InMemLogger;
910
using Microsoft.Extensions.DependencyInjection;
1011
using Microsoft.Extensions.Logging;
1112

@@ -18,12 +19,17 @@ public class AssembleFixture : IAsyncLifetime
1819
{
1920
public DistributedApplication DistributedApplication { get; private set; } = null!;
2021

22+
public InMemoryLogger InMemoryLogger { get; private set; } = null!;
23+
2124
/// <inheritdoc />
2225
public async ValueTask InitializeAsync()
2326
{
2427
var builder = await DistributedApplicationTestingBuilder.CreateAsync<Projects.Elastic_Documentation_Aspire>();
2528
_ = builder.Services.AddAppLogging(LogLevel.Information);
29+
_ = builder.Services.AddLogging(c => c.AddXUnit());
30+
_ = builder.Services.AddLogging(c => c.AddInMemory());
2631
DistributedApplication = await builder.BuildAsync();
32+
InMemoryLogger = DistributedApplication.Services.GetService<InMemoryLogger>()!;
2733
await DistributedApplication.StartAsync();
2834
}
2935

@@ -38,7 +44,8 @@ public async ValueTask DisposeAsync()
3844

3945
}
4046

41-
public class DatabaseTestClass1(AssembleFixture fixture, ITestOutputHelper output)
47+
48+
public class DatabaseTestClass1(AssembleFixture fixture, ITestOutputHelper output) : IAsyncLifetime
4249
{
4350
[Fact]
4451
public async Task X()
@@ -52,5 +59,17 @@ public async Task X()
5259
}
5360

5461

55-
// ...
62+
/// <inheritdoc />
63+
public ValueTask DisposeAsync()
64+
{
65+
GC.SuppressFinalize(this);
66+
if (TestContext.Current.TestState?.Result is TestResult.Passed)
67+
return default;
68+
foreach (var resource in fixture.InMemoryLogger.RecordedLogs)
69+
output.WriteLine(resource.Message);
70+
return default;
71+
}
72+
73+
/// <inheritdoc />
74+
public ValueTask InitializeAsync() => default;
5675
}

tests-integration/Elastic.Assembler.IntegrationTests/Elastic.Assembler.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<ItemGroup>
1717
<PackageReference Include="Aspire.Hosting.Testing" />
18+
<PackageReference Include="InMemoryLogger" />
1819
</ItemGroup>
1920

2021
</Project>

0 commit comments

Comments
 (0)