Skip to content

Commit 4bfbe42

Browse files
committed
Make sure that logger factory is there
1 parent 2084fa2 commit 4bfbe42

File tree

11 files changed

+25
-18
lines changed

11 files changed

+25
-18
lines changed

src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/StoreFixtureBase.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
using Bogus;
33
using DotNet.Testcontainers.Containers;
44
using Eventuous.TestHelpers;
5+
using Eventuous.TestHelpers.TUnit.Logging;
56
using Microsoft.Extensions.DependencyInjection;
67
using Microsoft.Extensions.Hosting;
8+
using Microsoft.Extensions.Logging;
79
using TUnit.Core.Interfaces;
810

911
namespace Eventuous.Tests.Persistence.Base.Fixtures;
@@ -18,7 +20,7 @@ public abstract class StoreFixtureBase {
1820
public TypeMapper TypeMapper { get; } = new();
1921
}
2022

21-
public abstract partial class StoreFixtureBase<TContainer> : StoreFixtureBase, IStartableFixture where TContainer : DockerContainer {
23+
public abstract partial class StoreFixtureBase<TContainer>(LogLevel logLevel) : StoreFixtureBase, IStartableFixture where TContainer : DockerContainer {
2224
public virtual async Task InitializeAsync() {
2325
Container = CreateContainer();
2426
await Container.StartAsync();
@@ -28,6 +30,7 @@ public virtual async Task InitializeAsync() {
2830
Serializer = new DefaultEventSerializer(TestPrimitives.DefaultOptions, TypeMapper);
2931
services.AddSingleton(Serializer);
3032
services.AddSingleton(TypeMapper);
33+
services.AddLogging(b => ConfigureLogging(b.ForTests(logLevel)).SetMinimumLevel(logLevel));
3134
SetupServices(services);
3235

3336
Provider = services.BuildServiceProvider();
@@ -43,9 +46,11 @@ protected async Task Start() {
4346
var inits = Provider.GetServices<IHostedService>();
4447

4548
foreach (var hostedService in inits) {
46-
await hostedService.StartAsync(default);
49+
await hostedService.StartAsync(CancellationToken.None);
4750
}
4851
}
52+
53+
protected virtual ILoggingBuilder ConfigureLogging(ILoggingBuilder builder) => builder;
4954

5055
public virtual async ValueTask DisposeAsync() {
5156
if (_disposed) return;
@@ -54,7 +59,7 @@ public virtual async ValueTask DisposeAsync() {
5459
var inits = Provider.GetServices<IHostedService>();
5560

5661
foreach (var hostedService in inits) {
57-
await hostedService.StopAsync(default);
62+
await hostedService.StopAsync(CancellationToken.None);
5863
}
5964

6065
await Provider.DisposeAsync();

src/Core/test/Eventuous.Tests.Subscriptions.Base/Fixtures/SubscriptionFixtureBase.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Eventuous.Subscriptions;
33
using Eventuous.Subscriptions.Checkpoints;
44
using Eventuous.Sut.Domain;
5-
using Eventuous.TestHelpers.TUnit.Logging;
65
using Eventuous.Tests.Persistence.Base.Fixtures;
76
using Microsoft.Extensions.DependencyInjection;
87
using Microsoft.Extensions.Hosting;
@@ -19,11 +18,9 @@ public abstract class SubscriptionFixtureBase<TContainer, TSubscription, TSubscr
1918
where TSubscription : EventSubscription<TSubscriptionOptions>
2019
where TSubscriptionOptions : SubscriptionOptions {
2120
readonly bool _autoStart;
22-
readonly LogLevel _logLevel;
2321

24-
protected SubscriptionFixtureBase(bool autoStart = true, LogLevel logLevel = LogLevel.Information) {
22+
protected SubscriptionFixtureBase(bool autoStart = true, LogLevel logLevel = LogLevel.Information) : base(logLevel) {
2523
_autoStart = autoStart;
26-
_logLevel = logLevel;
2724
TypeMapper.RegisterKnownEventTypes(typeof(BookingEvents.BookingImported).Assembly);
2825
}
2926

@@ -58,7 +55,6 @@ protected override void SetupServices(IServiceCollection services) {
5855

5956
var host = services.First(x => !x.IsKeyedService && x.ImplementationFactory?.GetType() == typeof(Func<IServiceProvider, SubscriptionHostedService>));
6057
services.Remove(host);
61-
services.AddLogging(b => ConfigureLogging(b.ForTests(_logLevel)).SetMinimumLevel(_logLevel));
6258
}
6359

6460
protected override void GetDependencies(IServiceProvider provider) {

src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/Fixtures/MetricsSubscriptionFixtureBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Eventuous.Tests.Persistence.Base.Fixtures;
66
using Eventuous.Tests.Subscriptions.Base;
77
using Microsoft.Extensions.Hosting;
8+
using Microsoft.Extensions.Logging;
89

910
namespace Eventuous.Tests.OpenTelemetry.Fixtures;
1011

@@ -30,7 +31,7 @@ public abstract class MetricsSubscriptionFixtureBase<TContainer, TProducer, TSub
3031
// ReSharper disable once StaticMemberInGenericType
3132
static readonly KeyValuePair<string, string> DefaultTag = new("test", "foo");
3233

33-
protected MetricsSubscriptionFixtureBase() {
34+
protected MetricsSubscriptionFixtureBase() : base(LogLevel.Information) {
3435
TypeMapper.RegisterKnownEventTypes(typeof(TestEvent).Assembly);
3536
}
3637

src/EventStore/test/Eventuous.Tests.EventStore/Fixtures/StoreFixture.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ public class StoreFixture : StoreFixtureBase<EventStoreDbContainer> {
1919

2020
static StoreFixture() => AppContext.SetSwitch("System.Net.SocketsHttpHandler.Http2FlowControl.DisableDynamicWindowSizing", true);
2121

22-
public StoreFixture() => ActivitySource.AddActivityListener(_listener);
22+
public StoreFixture() : this(LogLevel.Information) { }
23+
24+
public StoreFixture(LogLevel logLevel) : base(logLevel) {
25+
ActivitySource.AddActivityListener(_listener);
26+
}
2327

2428
protected override void SetupServices(IServiceCollection services) {
2529
services.AddEventStoreClient(Container.GetConnectionString());

src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/Fixtures/LegacySubscriptionFixture.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
namespace Eventuous.Tests.EventStore.Subscriptions.Fixtures;
99

10-
public abstract class LegacySubscriptionFixture<T>: IAsyncInitializer, IAsyncDisposable where T : class, IEventHandler {
10+
public abstract class LegacySubscriptionFixture<T> : IAsyncInitializer, IAsyncDisposable where T : class, IEventHandler {
1111
protected StreamName Stream { get; } = new($"test-{Guid.NewGuid():N}");
12-
protected StoreFixture StoreFixture { get; } = new();
12+
protected StoreFixture StoreFixture { get; }
1313
protected T Handler { get; }
1414
protected EventStoreProducer Producer { get; private set; } = null!;
1515
protected ILogger Log { get; }
@@ -19,6 +19,7 @@ public abstract class LegacySubscriptionFixture<T>: IAsyncInitializer, IAsyncDis
1919
protected LegacySubscriptionFixture(T handler, StreamName? stream = null, LogLevel logLevel = LogLevel.Information) {
2020
if (stream is { } s) Stream = s;
2121

22+
StoreFixture = new(logLevel);
2223
LoggerFactory = LoggingExtensions.GetLoggerFactory(logLevel);
2324
Handler = handler;
2425
Log = LoggerFactory.CreateLogger(GetType());

src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/Fixtures/PersistentSubscriptionFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class PersistentSubscriptionFixture<TSubscription, TOptions, THandler>(
1919
public THandler Handler { get; } = handler;
2020
public EventStoreProducer Producer { get; private set; } = null!;
2121
protected ILogger Log { get; set; } = null!;
22-
protected StoreFixture Fixture { get; } = new();
22+
protected StoreFixture Fixture { get; } = new(logLevel);
2323
TSubscription Subscription { get; set; } = null!;
2424

2525
public ValueTask Start() => Subscription.SubscribeWithLog(Log);

src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/StreamSubscriptionDeletedEventsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public sealed class StreamSubscriptionDeletedEventsTests {
1616
readonly LoggingEventListener _listener;
1717

1818
public StreamSubscriptionDeletedEventsTests() {
19-
_fixture = new();
19+
_fixture = new(LogLevel.Information);
2020
_loggerFactory = LoggingExtensions.GetLoggerFactory();
2121
_listener = new(_loggerFactory);
2222
_fixture.TypeMapper.RegisterKnownEventTypes(typeof(BookingEvents.BookingImported).Assembly);

src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/StreamSubscriptionWithLinksTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class StreamSubscriptionWithLinksTests : StoreFixture {
1616
readonly List<Checkpoint> _checkpoints = [];
1717
readonly string _prefix = $"{Faker.Commerce.ProductAdjective()}{Faker.Commerce.Product()}";
1818

19-
public StreamSubscriptionWithLinksTests() {
19+
public StreamSubscriptionWithLinksTests() : base(LogLevel.Information) {
2020
AutoStart = false;
2121
TypeMapper.AddType<TestEvent>(TestEvent.TypeName);
2222
}

src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/SubscriptionIgnoredMessagesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class SubscriptionIgnoredMessagesTests : StoreFixture {
1414
ICheckpointStore _checkpointStore = null!;
1515
TestEventHandler _handler = null!;
1616

17-
public SubscriptionIgnoredMessagesTests() {
17+
public SubscriptionIgnoredMessagesTests() : base(LogLevel.Information) {
1818
AutoStart = false;
1919
}
2020

src/Postgres/test/Eventuous.Tests.Postgres/Store/StoreFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Eventuous.Tests.Postgres.Store;
99

1010
// ReSharper disable once PartialTypeWithSinglePart
11-
public partial class StoreFixture : StoreFixtureBase<PostgreSqlContainer> {
11+
public partial class StoreFixture() : StoreFixtureBase<PostgreSqlContainer>(LogLevel.Information) {
1212
protected NpgsqlDataSource DataSource { get; private set; } = null!;
1313

1414
readonly string _schemaName = GetSchemaName();

0 commit comments

Comments
 (0)