Skip to content

Commit

Permalink
Add repro for event forwarding routing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
anhtin authored and jeremydmiller committed Jun 13, 2024
1 parent dda0488 commit be16b98
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/Persistence/MartenTests/Bugs/event_forwarding_routing_bug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using IntegrationTests;
using Marten;
using Marten.Events;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Shouldly;
using Wolverine;
using Wolverine.Marten;

namespace MartenTests.Bugs;

public class event_forwarding_routing_bug
{
[Fact]
public async Task forwarded_events_respects_routing_rules()
{
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.PublishAllMessages().ToLocalQueue("forwarded-events");
opts.Services.AddMarten(m =>
{
m.Connection(Servers.PostgresConnectionString);
m.DatabaseSchemaName = "forwarding_routing";
})
.IntegrateWithWolverine()
.EventForwardingToWolverine();
})
.StartAsync();

var bus = host.Services.GetRequiredService<IMessageBus>();
bus.PreviewSubscriptions(new Event<SomeEvent>(new SomeEvent()))
.ShouldAllBe(x => x.Destination == new Uri("local://forwarded-events"));
}

[Fact]
public async Task subscription_events_respects_routing_rules()
{
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.PublishAllMessages().ToLocalQueue("forwarded-events");
opts.Services.AddMarten(m =>
{
m.Connection(Servers.PostgresConnectionString);
m.DatabaseSchemaName = "forwarding_routing";
})
.IntegrateWithWolverine()
.PublishEventsToWolverine("forwarded-events");
})
.StartAsync();

var bus = host.Services.GetRequiredService<IMessageBus>();
bus.PreviewSubscriptions(new Event<SomeEvent>(new SomeEvent()))
.ShouldAllBe(x => x.Destination == new Uri("local://forwarded-events"));
}

public record SomeEvent;

public static class SomeEventHandler
{
public static void Handle(IEvent<SomeEvent> _)
{
}
}
}

0 comments on commit be16b98

Please sign in to comment.