[ServiceBus] Fix flaky test_backoff_fixed_retry by mocking time.sleep#46987
Merged
Conversation
The test previously measured wall-clock time around real time.sleep(0.8) calls and asserted the duration was strictly less than 1.6 seconds. On slow CI agents (notably macOS hosts) the elapsed time can exceed the budget by a few ms (e.g., 1.6399s observed in PR #46953), causing intermittent failures. Mock time.sleep in azure.servicebus._base_handler and assert the value passed to sleep instead. This is deterministic and ~80x faster. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes the Service Bus fixed retry backoff test deterministic by mocking time.sleep instead of measuring elapsed wall-clock time, reducing flakiness on slow CI agents.
Changes:
- Replaces real sleep timing assertions with a mocked
_base_handler.time.sleepassertion. - Consolidates duplicated fixed retry checks across string and enum retry modes.
- Verifies queue/topic senders and receivers all use the fixed backoff value.
EldertGrootenboer
approved these changes
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Make ests/test_sb_client.py::TestServiceBusClient::test_backoff_fixed_retry deterministic by mocking ime.sleep instead of measuring wall-clock duration around real sleeps.
Why
The test previously called _backoff(retried_times=1) (which sleeps 0.8s in fixed mode) and asserted ime.time() - start_time < backoff * 2 (i.e. < 1.6s). On slow CI hosts, OS scheduling jitter can push the elapsed time over the budget. Observed in PR #46953 CI run (macos311 agent):
How
azure.servicebus._base_handler.time.sleepand assert the value passed (==retry_backoff_factorfor fixed mode)."fixed"/RetryMode.Fixedinto a single helper.