Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MessageLockLost event test #38021

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
JoshLove-msft marked this conversation as resolved.
Show resolved Hide resolved
{
tcs.SetResult(true);
}
}
processor.ProcessMessageAsync += ProcessMessage;
processor.ProcessErrorAsync += ServiceBusTestUtilities.ExceptionHandler;
Expand Down