Skip to content

Commit

Permalink
Removed cleaning up read model database for Simple ESDB tests, as tha…
Browse files Browse the repository at this point in the history
…t may cause issues when test was interrupted in CI
  • Loading branch information
oskardudycz committed May 17, 2024
1 parent 5e858e7 commit a9f3872
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Core.EventStoreDB;
using Core.EventStoreDB.Commands;
using Core.EventStoreDB.Events;
using Core.EventStoreDB.Subscriptions;
using Core.OpenTelemetry;
using Core.Testing;
using EventStore.Client;
Expand Down Expand Up @@ -47,7 +48,7 @@ public EventStoreDBAsyncCommandBusTests()
{
ConnectionString = "esdb://localhost:2113?tls=false"
})
.AddEventStoreDBSubscriptionToAll()
.AddEventStoreDBSubscriptionToAll(new EventStoreDBSubscriptionToAllOptions(){SubscriptionId = "AsyncCommandBusTest"})
.AddCommandHandler<AddUser, AddUserCommandHandler>(
_ => new AddUserCommandHandler(userIds)
)
Expand Down
8 changes: 2 additions & 6 deletions Core.EventStoreDB/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static IServiceCollection AddEventStoreDB(

public static IServiceCollection AddEventStoreDBSubscriptionToAll(
this IServiceCollection services,
EventStoreDBSubscriptionToAllOptions? subscriptionOptions = null,
EventStoreDBSubscriptionToAllOptions subscriptionOptions,
bool checkpointToEventStoreDB = true)
{
if (checkpointToEventStoreDB)
Expand All @@ -77,11 +77,7 @@ public static IServiceCollection AddEventStoreDBSubscriptionToAll(

return new BackgroundWorker(
logger,
ct =>
eventStoreDBSubscriptionToAll.SubscribeToAll(
subscriptionOptions ?? new EventStoreDBSubscriptionToAllOptions(),
ct
)
ct => eventStoreDBSubscriptionToAll.SubscribeToAll(subscriptionOptions, ct)
);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Core.Events;
using Core.EventStoreDB.Events;
using Core.OpenTelemetry;
using Core.Threading;
using EventStore.Client;
using Grpc.Core;
using Microsoft.Extensions.Logging;
Expand All @@ -12,7 +11,7 @@ namespace Core.EventStoreDB.Subscriptions;

public class EventStoreDBSubscriptionToAllOptions
{
public string SubscriptionId { get; set; } = "default";
public required string SubscriptionId { get; init; }

public SubscriptionFilterOptions FilterOptions { get; set; } =
new(EventTypeFilter.ExcludeSystemEvents());
Expand All @@ -34,16 +33,13 @@ ILogger<EventStoreDBSubscriptionToAll> logger
{
private EventStoreDBSubscriptionToAllOptions subscriptionOptions = default!;
private string SubscriptionId => subscriptionOptions.SubscriptionId;
private readonly object resubscribeLock = new();
private CancellationToken cancellationToken;

public async Task SubscribeToAll(EventStoreDBSubscriptionToAllOptions subscriptionOptions, CancellationToken ct)
{
// see: https://github.com/dotnet/runtime/issues/36063
await Task.Yield();

this.subscriptionOptions = subscriptionOptions;
cancellationToken = ct;

logger.LogInformation("Subscription to all '{SubscriptionId}'", subscriptionOptions.SubscriptionId);

Expand Down
3 changes: 2 additions & 1 deletion Sample/EventStoreDB/ECommerce/Carts/Carts.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Carts;
using Core;
using Core.EventStoreDB;
using Core.EventStoreDB.Subscriptions;
using Core.Exceptions;
using Core.OpenTelemetry;
using Core.WebApi.Middlewares.ExceptionHandling;
Expand All @@ -27,7 +28,7 @@
WrongExpectedVersionException => exception.MapToProblemDetails(StatusCodes.Status412PreconditionFailed),
_ => null
})
.AddEventStoreDBSubscriptionToAll()
.AddEventStoreDBSubscriptionToAll(new EventStoreDBSubscriptionToAllOptions { SubscriptionId = "DDDESDB" })
.AddCartsModule(builder.Configuration)
.AddOptimisticConcurrencyMiddleware()
.AddOpenTelemetry("Carts", OpenTelemetryOptions.Build(options =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ namespace ECommerce.Api.Tests;

public class ShoppingCartsApplicationFactory: TestWebApplicationFactory<Program>
{
protected override IHost CreateHost(IHostBuilder builder)
{
var host = base.CreateHost(builder);

using var scope = host.Services.CreateScope();
using var context = scope.ServiceProvider.GetRequiredService<ECommerceDbContext>();
var database = context.Database;
database.ExecuteSqlRaw("TRUNCATE TABLE \"ShoppingCartDetailsProductItem\"");
database.ExecuteSqlRaw("TRUNCATE TABLE \"ShoppingCartShortInfo\"");
database.ExecuteSqlRaw("TRUNCATE TABLE \"ShoppingCartDetails\" CASCADE");

return host;
}
// protected override IHost CreateHost(IHostBuilder builder)
// {
// var host = base.CreateHost(builder);
//
// using var scope = host.Services.CreateScope();
// using var context = scope.ServiceProvider.GetRequiredService<ECommerceDbContext>();
// var database = context.Database;
// database.ExecuteSqlRaw("TRUNCATE TABLE \"ShoppingCartDetailsProductItem\"");
// database.ExecuteSqlRaw("TRUNCATE TABLE \"ShoppingCartShortInfo\"");
// database.ExecuteSqlRaw("TRUNCATE TABLE \"ShoppingCartDetails\" CASCADE");
//
// return host;
// }
}
3 changes: 2 additions & 1 deletion Sample/EventStoreDB/Simple/ECommerce.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Net;
using Core.EventStoreDB;
using Core.EventStoreDB.Subscriptions;
using Core.Exceptions;
using Core.OpenTelemetry;
using Core.WebApi.Middlewares.ExceptionHandling;
Expand Down Expand Up @@ -27,7 +28,7 @@
WrongExpectedVersionException => exception.MapToProblemDetails(StatusCodes.Status412PreconditionFailed),
_ => null
})
.AddEventStoreDBSubscriptionToAll()
.AddEventStoreDBSubscriptionToAll(new EventStoreDBSubscriptionToAllOptions { SubscriptionId = "SimpleESDB"})
.AddECommerceModule(builder.Configuration)
.AddOptimisticConcurrencyMiddleware()
.AddOpenTelemetry("Carts", OpenTelemetryOptions.Build(options =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ public async Task Handle(EventEnvelope<TEvent> eventEnvelope, CancellationToken
switch (view)
{
case null:
throw new InvalidOperationException($"{typeof(TView).Name} with id {viewId} wasn't found");
throw new InvalidOperationException($"{typeof(TView).Name} with id {viewId} wasn't found for event {typeof(TEvent).Name}");
case ITrackLastProcessedPosition tracked when tracked.LastProcessedPosition <= eventEnvelope.Metadata.LogPosition:
logger.LogWarning(
"{View} with id {ViewId} was already processe. LastProcessedPosition: {LastProcessedPosition}), event LogPosition: {LogPosition}",
"{View} with id {ViewId} was already processed. LastProcessedPosition: {LastProcessedPosition}), event LogPosition: {LogPosition}",
typeof(TView).Name,
viewId,
tracked.LastProcessedPosition,
Expand Down

0 comments on commit a9f3872

Please sign in to comment.