Skip to content

Commit

Permalink
MessageLockLostException should not trigger critical errors (#73)
Browse files Browse the repository at this point in the history
MessageLockLostException should not trigger critical errors
  • Loading branch information
SeanFeldman authored Aug 23, 2019
2 parents 71a3cb0 + 65aa41b commit cdb541e
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Transport/Receiving/MessagePump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ async Task ProcessMessage(Task<Message> receiveTask)
await receiver.SafeAbandonAsync(pushSettings.RequiredTransactionMode, lockToken).ConfigureAwait(false);
}
}
catch (Exception onErrorException) when (onErrorException is MessageLockLostException || onErrorException is ServiceBusTimeoutException)
{
logger.Debug("Failed to execute recoverability.", onErrorException);
}
catch (Exception onErrorException)
{
criticalError.Raise($"Failed to execute recoverability policy for message with native ID: `{message.MessageId}`", onErrorException);
Expand Down
54 changes: 54 additions & 0 deletions src/TransportTests/When_MessageLockLostException_is_thrown.cs
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 src/TransportTests/When_ServiceBusTimeoutException_is_thrown.cs
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);
}
}
}

0 comments on commit cdb541e

Please sign in to comment.