From 02923ffab4744e5509b3b2da1ebfe5d6ffda5736 Mon Sep 17 00:00:00 2001 From: Jesse Squire Date: Wed, 29 May 2024 10:04:48 -0400 Subject: [PATCH] [Service Bus] Batch delete test tweaks (#44282) 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. --- .../tests/Receiver/ReceiverLiveTests.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Receiver/ReceiverLiveTests.cs b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Receiver/ReceiverLiveTests.cs index 9792ecd908fb2..4df4584181f81 100644 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Receiver/ReceiverLiveTests.cs +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/tests/Receiver/ReceiverLiveTests.cs @@ -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(); @@ -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)); @@ -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();