Skip to content

Commit

Permalink
Reduce test logging
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Dec 22, 2024
1 parent 6d52264 commit 4007e08
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public virtual async ValueTask DisposeAsync() {

await Provider.DisposeAsync();
await Container.DisposeAsync();
GC.SuppressFinalize(this);
}

protected abstract void SetupServices(IServiceCollection services);
Expand All @@ -76,7 +77,7 @@ protected virtual void GetDependencies(IServiceProvider provider) { }

bool _disposed;

public static string GetSchemaName() => NormaliseRegex().Replace(new Faker().Internet.UserName(), "").ToLower();
protected static string GetSchemaName() => NormaliseRegex().Replace(new Faker().Internet.UserName(), "").ToLower();

#if NET8_0_OR_GREATER
[GeneratedRegex(@"[\.\-\s]")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

namespace Eventuous.Tests.Subscriptions.Base;

public abstract class SubscriptionFixtureBase<TContainer, TSubscription, TSubscriptionOptions, TCheckpointStore, TEventHandler>
: StoreFixtureBase<TContainer>, IStartableFixture
public abstract class SubscriptionFixtureBase<TContainer, TSubscription, TSubscriptionOptions, TCheckpointStore, TEventHandler> : StoreFixtureBase<TContainer>
where TEventHandler : class, IEventHandler
where TContainer : DockerContainer
where TCheckpointStore : class, ICheckpointStore
Expand All @@ -22,7 +21,7 @@ public abstract class SubscriptionFixtureBase<TContainer, TSubscription, TSubscr
readonly bool _autoStart;
readonly LogLevel _logLevel;

protected SubscriptionFixtureBase(bool autoStart = true, LogLevel logLevel = LogLevel.Trace) {
protected SubscriptionFixtureBase(bool autoStart = true, LogLevel logLevel = LogLevel.Information) {
_autoStart = autoStart;
_logLevel = logLevel;
TypeMapper.RegisterKnownEventTypes(typeof(BookingEvents.BookingImported).Assembly);
Expand Down Expand Up @@ -55,9 +54,7 @@ protected override void SetupServices(IServiceCollection services) {
}
);

services.AddSingleton<IMessageSubscription>(
sp => sp.GetSubscriptionBuilder<TSubscription, TSubscriptionOptions>(SubscriptionId).ResolveSubscription(sp)
);
services.AddSingleton<IMessageSubscription>(sp => sp.GetSubscriptionBuilder<TSubscription, TSubscriptionOptions>(SubscriptionId).ResolveSubscription(sp));

var host = services.First(x => !x.IsKeyedService && x.ImplementationFactory?.GetType() == typeof(Func<IServiceProvider, SubscriptionHostedService>));
services.Remove(host);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CatchUpSubscriptionFixture<TSubscription, TSubscriptionOptions, TEv
StreamName streamName,
bool autoStart = true,
Action<IServiceCollection>? configureServices = null,
LogLevel logLevel = LogLevel.Debug
LogLevel logLevel = LogLevel.Information
) : SubscriptionFixtureBase<EventStoreDbContainer, TSubscription, TSubscriptionOptions, TestCheckpointStore, TEventHandler>(autoStart, logLevel)
where TSubscription : EventStoreCatchUpSubscriptionBase<TSubscriptionOptions>
where TSubscriptionOptions : CatchUpSubscriptionOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ protected static NpgsqlCommand Project(NpgsqlConnection connection, string comma

return cmd;
}

protected static NpgsqlCommand Project(NpgsqlConnection connection, string commandText, params (string Name, object Value)[] parameters)
=> Project(connection, commandText, parameters.Select(x => new NpgsqlParameter(x.Name, x.Value)).ToArray());
}

public delegate NpgsqlCommand ProjectToPostgres<T>(NpgsqlConnection connection, MessageConsumeContext<T> consumeContext) where T : class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,7 @@ public TestProjector(NpgsqlDataSource dataSource, SchemaInfo schemaInfo) : base(
var insert = $"insert into {schemaInfo.Schema}.bookings (booking_id, checkin_date, price) values (@booking_id, @checkin_date, @price)";

On<BookingEvents.BookingImported>(
(connection, ctx) =>
Project(
connection,
insert,
new NpgsqlParameter("@booking_id", ctx.Stream.GetId()),
new NpgsqlParameter("@checkin_date", ctx.Message.CheckIn.ToDateTimeUnspecified()),
new NpgsqlParameter("@price", ctx.Message.Price)
)
(connection, ctx) => Project(connection, insert, ("@booking_id", ctx.Stream.GetId()), ("@checkin_date", ctx.Message.CheckIn.ToDateTimeUnspecified()), ("@price", ctx.Message.Price))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@ public class SubscriptionFixture<TSubscription, TSubscriptionOptions, TEventHand
Action<TSubscriptionOptions> configureOptions,
bool autoStart = true,
Action<IServiceCollection>? configureServices = null,
LogLevel logLevel = LogLevel.Debug
)
: SubscriptionFixtureBase<PostgreSqlContainer, TSubscription, TSubscriptionOptions, PostgresCheckpointStore, TEventHandler>(
autoStart,
logLevel
LogLevel logLevel = LogLevel.Information
)
: SubscriptionFixtureBase<PostgreSqlContainer, TSubscription, TSubscriptionOptions, PostgresCheckpointStore, TEventHandler>(autoStart, logLevel)
where TSubscription : PostgresSubscriptionBase<TSubscriptionOptions>
where TSubscriptionOptions : PostgresSubscriptionBaseOptions
where TEventHandler : class, IEventHandler {
protected internal readonly string SchemaName = GetSchemaName();

protected override PostgreSqlContainer CreateContainer() => PostgresContainer.Create();

protected override PostgresCheckpointStore GetCheckpointStore(IServiceProvider sp)
=> sp.GetRequiredService<PostgresCheckpointStore>();
protected override PostgresCheckpointStore GetCheckpointStore(IServiceProvider sp) => sp.GetRequiredService<PostgresCheckpointStore>();

protected override void ConfigureSubscription(TSubscriptionOptions options) {
options.Schema = SchemaName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class SubscriptionFixture<TSubscription, TSubscriptionOptions, TEventHand
Action<TSubscriptionOptions> configureOptions,
bool autoStart = true,
Action<IServiceCollection>? configureServices = null,
LogLevel logLevel = LogLevel.Debug
LogLevel logLevel = LogLevel.Information
)
: SubscriptionFixtureBase<MsSqlContainer, TSubscription, TSubscriptionOptions, SqlServerCheckpointStore, TEventHandler>(
autoStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static ILoggerFactory AddTUnit(this ILoggerFactory factory) {

public static ILoggingBuilder AddTUnit(this ILoggingBuilder builder) => builder.AddProvider(new TUnitLoggerProvider());

public static ILoggingBuilder ForTests(this ILoggingBuilder builder, LogLevel logLevel = LogLevel.Debug)
public static ILoggingBuilder ForTests(this ILoggingBuilder builder, LogLevel logLevel = LogLevel.Information)
=> builder.AddTUnit().SetMinimumLevel(logLevel).AddFilter("Grpc", LogLevel.Warning).AddFilter("Microsoft", LogLevel.Warning);
}

Expand Down

0 comments on commit 4007e08

Please sign in to comment.