AzureServiceBusAPMTests flakiness fix. #8050
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of changes
Fixes flaky TestReceiveMessagesAsyncIntegration test in Azure Service Bus APM integration tests by ensuring scheduled messages are delivered before queue cleanup.
Reason for change
The TestReceiveMessagesAsyncIntegration test was intermittently failing in CI with the error:
This occurred because the test was receiving messages scheduled by previous TestScheduleMessagesAsyncIntegration test runs, but the corresponding send spans were not available (they were from a different test execution).
The race condition occurred due to the timing of scheduled message delivery:
- If delivery is delayed beyond the 2-second PurgeQueue window, messages escape cleanup
- These orphaned scheduled messages get received by subsequent TestReceiveMessagesAsync test runs
- The test fails because it can't find the corresponding send spans (they were in a different test run)
The test usually passed because:
It failed when:
Implementation details
Modified TestScheduleMessagesAsync in Samples.AzureServiceBus.APM/Program.cs to wait for scheduled messages to be delivered before returning:
This ensures:
Test coverage
This change fixes the existing integration test rather than adding new tests. The fix eliminates the race condition entirely rather than masking it with retries.
Other details