Skip to content

Commit

Permalink
Fix MessageLockLost event test (#38021)
Browse files Browse the repository at this point in the history
* Fix MessageLockLost event test

* wrap in try/finally
  • Loading branch information
JoshLove-msft authored Aug 4, 2023
1 parent 2d24f5f commit c54b343
Showing 1 changed file with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1491,10 +1491,16 @@ async Task ProcessMessage(ProcessMessageEventArgs args)
};
await args.CompleteMessageAsync(args.Message);
await Task.Delay(lockDuration.Add(lockDuration));
Assert.IsTrue(messageLockLostRaised);
Assert.IsTrue(args.MessageLockCancellationToken.IsCancellationRequested);
Assert.IsFalse(args.CancellationToken.IsCancellationRequested);
tcs.SetResult(true);
try
{
Assert.IsTrue(messageLockLostRaised);
Assert.IsTrue(args.MessageLockCancellationToken.IsCancellationRequested);
Assert.IsFalse(args.CancellationToken.IsCancellationRequested);
}
finally
{
tcs.SetResult(true);
}
}
processor.ProcessMessageAsync += ProcessMessage;
processor.ProcessErrorAsync += ServiceBusTestUtilities.ExceptionHandler;
Expand All @@ -1505,8 +1511,13 @@ async Task ProcessMessage(ProcessMessageEventArgs args)
}
}

/// <summary>
/// Because the message lock renewal occurs on the mgmt link, even when the connection drops, message lock renewal continues
/// successfully. This is in contrast to session messages where the lock renewal requires the session to be locked,
/// so when the connection drops, the session is lost and the lock renewal fails.
/// </summary>
[Test]
public async Task MessageLockLostEventRaisedAfterConnectionDropped()
public async Task MessageLockLostEventNotRaisedAfterConnectionDropped()
{
var lockDuration = TimeSpan.FromSeconds(30);
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: false, lockDuration: lockDuration))
Expand Down Expand Up @@ -1534,10 +1545,16 @@ async Task ProcessMessage(ProcessMessageEventArgs args)
};
SimulateNetworkFailure(client);
await Task.Delay(lockDuration.Add(lockDuration));
Assert.IsTrue(messageLockLostRaised);
Assert.IsTrue(args.MessageLockCancellationToken.IsCancellationRequested);
Assert.IsFalse(args.CancellationToken.IsCancellationRequested);
tcs.SetResult(true);
try
{
Assert.IsFalse(messageLockLostRaised);
Assert.IsFalse(args.MessageLockCancellationToken.IsCancellationRequested);
Assert.IsFalse(args.CancellationToken.IsCancellationRequested);
}
finally
{
tcs.SetResult(true);
}
}
processor.ProcessMessageAsync += ProcessMessage;
processor.ProcessErrorAsync += ServiceBusTestUtilities.ExceptionHandler;
Expand Down

0 comments on commit c54b343

Please sign in to comment.