-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MessageLockLostException should not trigger critical errors (#73)
MessageLockLostException should not trigger critical errors
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/TransportTests/When_MessageLockLostException_is_thrown.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace NServiceBus.Transport.AzureServiceBus.TransportTests | ||
{ | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.ServiceBus; | ||
using NServiceBus.TransportTests; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class When_MessageLockLostException_is_thrown : NServiceBusTransportTest | ||
{ | ||
[TestCase(TransportTransactionMode.None)] | ||
[TestCase(TransportTransactionMode.ReceiveOnly)] | ||
[TestCase(TransportTransactionMode.SendsAtomicWithReceive)] | ||
public async Task Should_not_raise_critical_error(TransportTransactionMode transactionMode) | ||
{ | ||
var criticalErrorInvoked = new TaskCompletionSource<bool>(); | ||
var criticalErrorCalled = false; | ||
|
||
OnTestTimeout(() => criticalErrorInvoked.SetResult(false)); | ||
|
||
var firstInvocation = true; | ||
|
||
await StartPump( | ||
context => | ||
{ | ||
if (firstInvocation) | ||
{ | ||
firstInvocation = false; | ||
throw new MessageLockLostException("from onMessage"); | ||
} | ||
|
||
return Task.CompletedTask; | ||
}, | ||
context => | ||
{ | ||
throw new MessageLockLostException("from onError"); | ||
}, | ||
transactionMode, | ||
(message, exception) => | ||
{ | ||
criticalErrorCalled = true; | ||
criticalErrorInvoked.SetResult(true); | ||
} | ||
); | ||
|
||
await SendMessage(InputQueueName); | ||
|
||
await criticalErrorInvoked.Task; | ||
|
||
Assert.IsFalse(criticalErrorCalled, $"Should not invoke critical error for {nameof(MessageLockLostException)}"); | ||
Assert.IsFalse(criticalErrorInvoked.Task.Result); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/TransportTests/When_ServiceBusTimeoutException_is_thrown.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace NServiceBus.Transport.AzureServiceBus.TransportTests | ||
{ | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.ServiceBus; | ||
using NServiceBus.TransportTests; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class When_ServiceBusTimeoutException_is_thrown : NServiceBusTransportTest | ||
{ | ||
[TestCase(TransportTransactionMode.None)] | ||
[TestCase(TransportTransactionMode.ReceiveOnly)] | ||
[TestCase(TransportTransactionMode.SendsAtomicWithReceive)] | ||
public async Task Should_not_raise_critical_error(TransportTransactionMode transactionMode) | ||
{ | ||
var criticalErrorInvoked = new TaskCompletionSource<bool>(); | ||
var criticalErrorCalled = false; | ||
|
||
OnTestTimeout(() => criticalErrorInvoked.SetResult(false)); | ||
|
||
var firstInvocation = true; | ||
|
||
await StartPump( | ||
context => | ||
{ | ||
if (firstInvocation) | ||
{ | ||
firstInvocation = false; | ||
throw new ServiceBusTimeoutException("from onMessage"); | ||
} | ||
|
||
return Task.CompletedTask; | ||
}, | ||
context => | ||
{ | ||
throw new ServiceBusTimeoutException("from onError"); | ||
}, | ||
transactionMode, | ||
(message, exception) => | ||
{ | ||
criticalErrorCalled = true; | ||
criticalErrorInvoked.SetResult(true); | ||
} | ||
); | ||
|
||
await SendMessage(InputQueueName); | ||
|
||
await criticalErrorInvoked.Task; | ||
|
||
Assert.IsFalse(criticalErrorCalled, $"Should not invoke critical error for {nameof(ServiceBusTimeoutException)}"); | ||
Assert.IsFalse(criticalErrorInvoked.Task.Result); | ||
} | ||
} | ||
} |