Speed up sonic_xcvr unit tests by patching time.sleep via autouse fixture#669
Merged
Merged
Conversation
Signed-off-by: aditya-nexthop <aditya@nexthop.ai>
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
prgeor
reviewed
May 20, 2026
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) |
Collaborator
There was a problem hiding this comment.
@aditya-nexthop you mean test case running sleep is waste of time?
Contributor
Author
There was a problem hiding this comment.
yes, if it does nothing useful, especially in a unit test with no real hardware behind it?
Contributor
There was a problem hiding this comment.
Pull request overview
This PR speeds up the tests/sonic_xcvr pytest suite by introducing an autouse fixture that patches time.sleep during each test run, eliminating real sleep delays from exercised production paths.
Changes:
- Add
tests/sonic_xcvr/conftest.pywith an autouse fixture that patchestime.sleepfor all tests undertests/sonic_xcvr.
Signed-off-by: aditya-nexthop <aditya@nexthop.ai>
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
prgeor
approved these changes
May 21, 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.
Description
Add an autouse pytest fixture in
tests/sonic_xcvr/conftest.pythatpatches
time.sleepfor every test in thetests/sonic_xcvrpackage.Motivation and Context
Several
tests/sonic_xcvrtests exercise production code paths thatcall
time.sleepdirectly, without mocking it. The suite thereforespends almost all of its wall time blocked in real sleeps:
test_cmisCDB.py::test_start_fw_downloadcmisCDB.py:288—time.sleep(MAX_CDB_CMD_FOREGROUND_PROCESSING_TIME_tCDBF)(5s)test_cmisCDB.py::test_validate_fw_imagecmisCDB.py:419— same 5s constanttest_cmis.py::test_resetcmis.py:1369—time.sleep(2)afterreset_module()test_cmisCDB.py::test_run_fw_imagecmisCDB.py:459—time.sleep(delay/1000)(delay ≈ 562 ms)test_ccmis.py::test_set_tx_powerc_cmis.py:187—time.sleep(1)These 12 test invocations account for ~35.7s of a ~36.7s suite — about
97% of the runtime.
How Has This Been Tested?
Ran the full
tests/sonic_xcvrsuite before and after the change.All 824 tests still pass; no behavior change. Suite is ~34× faster.
Additional Information (Optional)