public async Task Should_use_global_enable_transient() { using (var scope = NewScope()) { var db = scope.ServiceProvider.GetService <ApplicationDbContext>(); var outboxSession = new OutboxSession <ApplicationDbContext>(_fixture.Outbox, db); var endpoint = A.Fake <TestOutboundEndpoint>(x => x.WithArgumentsForConstructor(() => new TestOutboundEndpoint("TransientDispatchTestEndpoint1.1", null, null)) ); _fixture.MessagingService.AddEndpoint(endpoint); await _fixture.MessagingService.StartAsync(); await outboxSession.Dispatch(_fixture.Message.MessageType, _fixture.MessageBytes, null, endpoint, new OutboxDispatchOptions()); A.CallTo(() => endpoint.Dispatch(_fixture.Message.MessageType, _fixture.MessageBytes, null)).MustNotHaveHappened(); await db.SaveChangesAsync(); await Task.Delay(_delayForTransientProcessor); A.CallTo(() => endpoint.Dispatch(_fixture.Message.MessageType, _fixture.MessageBytes, null)).MustHaveHappenedOnceExactly(); } using (var scope = NewScope()) { var db = scope.ServiceProvider.GetService <ApplicationDbContext>(); var outboxMessages = db.Set <OutboxMessage>().Include(x => x.MessageData).OrderBy(x => x.CreatedAtUtc) .AsNoTracking().ToList(); var m = outboxMessages.Last(); m.Status.ShouldBe((int)OutboxMessageStatus.Processed, "status should be 2/Processed"); m.TryCount.ShouldBe(0);// we don't count the transient attempt towards outbox tries } }
public async Task Should_become_ready_on_transient_failure() { using (var scope = NewScope()) { var db = scope.ServiceProvider.GetService <ApplicationDbContext>(); var outboxSession = new OutboxSession <ApplicationDbContext>(_fixture.Outbox, db); var endpoint = A.Fake <TestOutboundEndpoint>(x => x.WithArgumentsForConstructor(() => new TestOutboundEndpoint("TransientDispatchTestEndpoint1.2", null, null)) ); _fixture.MessagingService.AddEndpoint(endpoint); await _fixture.MessagingService.StartAsync(); A.CallTo(() => endpoint.Dispatch(_fixture.Message.MessageType, _fixture.MessageBytes, null)) .Throws(new ApplicationException("Test:Forced failure of transient dispatch")); await outboxSession.Dispatch(_fixture.Message.MessageType, _fixture.MessageBytes, null, endpoint, new OutboxDispatchOptions()); A.CallTo(() => endpoint.Dispatch(_fixture.Message.MessageType, _fixture.MessageBytes, null)).MustNotHaveHappened(); await db.SaveChangesAsync(); await Task.Delay(_delayForTransientProcessor); A.CallTo(() => endpoint.Dispatch(_fixture.Message.MessageType, _fixture.MessageBytes, null)).MustHaveHappenedOnceExactly(); } using (var scope = NewScope()) { var db = scope.ServiceProvider.GetService <ApplicationDbContext>(); var outboxMessages = db.Set <OutboxMessage>().Include(x => x.MessageData).OrderBy(x => x.CreatedAtUtc) .AsNoTracking().ToList(); var m = outboxMessages.Last(); m.Status.ShouldBe((int)OutboxMessageStatus.Ready, "status should be 0/Ready"); } }
public async Task Should_fail_permnently_on_expired_message() { using (var scope = NewScope()) { var db = scope.ServiceProvider.GetService <ApplicationDbContext>(); var outboxSession = new OutboxSession <ApplicationDbContext>(_fixture.Outbox, db); var endpoint = A.Fake <TestOutboundEndpoint>(x => x.WithArgumentsForConstructor(() => new TestOutboundEndpoint("TransientDispatchTestEndpoint1.3", null, null)) ); _fixture.MessagingService.AddEndpoint(endpoint); await _fixture.MessagingService.StartAsync(); await outboxSession.Dispatch(_fixture.Message.MessageType, _fixture.MessageBytes, null, endpoint, new OutboxDispatchOptions() { ExpiresAtUtc = DateTime.UtcNow }); await db.SaveChangesAsync(); await Task.Delay(_delayForTransientProcessor); } using (var scope = NewScope()) { var db = scope.ServiceProvider.GetService <ApplicationDbContext>(); var outboxMessages = db.Set <OutboxMessage>().Include(x => x.MessageData).OrderBy(x => x.CreatedAtUtc) .AsNoTracking().ToList(); var m = outboxMessages.Last(); m.Status.ShouldBe((int)OutboxMessageStatus.Failed, "status should be 100/Failed"); } }
public async Task Should_abandon_transient_with_delay_when_endpoint_does_not_support_delay() { /* * public class TestTransport : Transport * { * public override bool SupportsDelayedDispatch => false; */ using (var scope = NewScope()) { var db = scope.ServiceProvider.GetService <ApplicationDbContext>(); var outboxSession = new OutboxSession <ApplicationDbContext>(_fixture.Outbox, db); var endpoint = A.Fake <TestOutboundEndpoint>(x => x.WithArgumentsForConstructor(() => new TestOutboundEndpoint("TransientDispatchTestEndpoint1.4", null, null)) ); _fixture.MessagingService.AddEndpoint(endpoint); await _fixture.MessagingService.StartAsync(); ///the configuration gets a little funky here because in normal use the ///end user uses metaData to configure delay while behind the scenes meta is ///used to set the the OutboxDispatchOptions, this test should probably be done ///on the MessagingService MessageMetaData meta = new MessageMetaData(TimeSpan.FromMinutes(1)); await outboxSession.Dispatch(_fixture.Message.MessageType, _fixture.MessageBytes, meta, endpoint, new OutboxDispatchOptions() { Delay = meta.DispatchDelay }); await db.SaveChangesAsync(); await Task.Delay(_delayForTransientProcessor); A.CallTo(() => endpoint.Dispatch(_fixture.Message.MessageType, _fixture.MessageBytes, null)).MustNotHaveHappened(); } using (var scope = NewScope()) { var db = scope.ServiceProvider.GetService <ApplicationDbContext>(); var outboxMessages = db.Set <OutboxMessage>().Include(x => x.MessageData).OrderBy(x => x.CreatedAtUtc) .AsNoTracking().ToList(); var m = outboxMessages.Last(); m.Status.ShouldBe((int)OutboxMessageStatus.Ready, "status should be 0/Ready"); } }
public async Task Should_overide_global_with_message_level_disable_transient() { using (var scope = NewScope()) { var db = scope.ServiceProvider.GetService <ApplicationDbContext>(); var outboxSession = new OutboxSession <ApplicationDbContext>(_fixture.Outbox, db); await outboxSession.Dispatch(_fixture.Message.MessageType, _fixture.MessageBytes, null, null, new OutboxDispatchOptions() { SkipTransientDispatch = true, }); await db.SaveChangesAsync(); } using (var scope = NewScope()) { var db = scope.ServiceProvider.GetService <ApplicationDbContext>(); var outboxMessages = db.Set <OutboxMessage>().Include(x => x.MessageData).OrderBy(x => x.CreatedAtUtc) .AsNoTracking().ToList(); var m = outboxMessages.Last(); m.Status.ShouldBe((int)OutboxMessageStatus.Ready, "status should be 0/Ready"); } }