Azure / azure-service-bus-dotnet

☁️ .NET Standard client library for Azure Service Bus
https://azure.microsoft.com/services/service-bus
Other
235 stars 120 forks source link

Fix TestUtility.ReceiveMessagesAsync loop condition #643

Closed SeanFeldman closed 5 years ago

SeanFeldman commented 5 years ago

To receive, TestUtility has to continue until one of the conditions is no longer fullfilled:

  1. Received messages >= messageCount OR
  2. receiveAttempts >= TestConstants.MaxAttemptsCount OR
  3. stopwatch.Elapsed >= timeout

The original code does OR between receive attempts check and timeout, rather than AND.

while (messagesToReturn.Count < messageCount 
&& (receiveAttempts++ < TestConstants.MaxAttemptsCount || stopwatch.Elapsed < timeout))

Meaning if the number of attempts is not exceeded, but timeout elapsed (or the opposite), the loop will continue running. The correct behaviour should be AND between all 3 conditions.