Skip to content

Commit

Permalink
[Service Bus] Batch delete test tweaks (Azure#44282)
Browse files Browse the repository at this point in the history
The focus of these changes is to fix the order of
"expected" and "actual" for the purge scenarios and
to add a short delay between publishing messages
and purging to ensure there is adequate time for
the messages to be made available in the queue.
  • Loading branch information
jsquire authored May 29, 2024
1 parent 7350c2a commit 02923ff
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1292,10 +1292,14 @@ public async Task PurgeMessages()
var messageCount = ServiceBusReceiver.MaxDeleteMessageCount * 3;
await SendMessagesAsync(client, scope.QueueName, messageCount);

// Delay a moment to ensure that the messages are available to
// read/delete.
await Task.Delay(TimeSpan.FromSeconds(2));

var receiver = client.CreateReceiver(scope.QueueName);
var numMessagesDeleted = await receiver.PurgeMessagesAsync();

Assert.AreEqual(numMessagesDeleted, messageCount);
Assert.AreEqual(messageCount, numMessagesDeleted);

// All messages should have been deleted.
var peekedMessage = receiver.PeekMessageAsync();
Expand All @@ -1313,7 +1317,12 @@ public async Task PurgeMessagesWithDate()
var messageCount = ServiceBusReceiver.MaxDeleteMessageCount * 3;
await SendMessagesAsync(client, scope.QueueName, messageCount);

var targetDate = DateTime.UtcNow.AddSeconds(1);
// Delay a moment to ensure that the messages are available to
// read/delete.
await Task.Delay(TimeSpan.FromSeconds(2));

// Mark the time for deleting.
var targetDate = DateTime.UtcNow;

// Wait a few seconds, then send a new message that should survive the purge.
await Task.Delay(TimeSpan.FromSeconds(15));
Expand All @@ -1324,7 +1333,7 @@ public async Task PurgeMessagesWithDate()
var receiver = client.CreateReceiver(scope.QueueName);
var numMessagesDeleted = await receiver.PurgeMessagesAsync(targetDate);

Assert.AreEqual(numMessagesDeleted, messageCount);
Assert.AreEqual(messageCount, numMessagesDeleted);

// All messages should have been deleted, except for our designated survivor.
var peekedMessage = receiver.PeekMessageAsync();
Expand Down

0 comments on commit 02923ff

Please sign in to comment.