Speed up execution of thermalctld unit tests#789
Merged
rlhui merged 2 commits intosonic-net:masterfrom Apr 22, 2026
Merged
Conversation
Signed-off-by: aditya-nexthop <aditya@nexthop.ai>
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
… swsssdk and remove the direct mocks in the test file Signed-off-by: aditya-nexthop <aditya@nexthop.ai>
0d36026 to
15c7f23
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
Author
|
@judyjoseph please can you take a look at this PR? |
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
Replace the real
swsssdkimports inmocked_libs/swsscommon/swsscommon.pywith mock stubs forConfigDBConnectorandSonicV2Connector, eliminating allswsssdkdependencies from the test environment, and add the missinggetKeys()method tomock_swsscommon.Table.Motivation and Context
The thermalctld test suite was taking ~36 minutes to run due to Redis connection timeouts incurred on every
TemperatureUpdaterconstruction.TemperatureUpdater.__init__calls_init_sfp_util_helper(), which invokesSfpUtilHelper().read_porttab_mappings(). This triggers up to 7 calls todevice_info.get_localhost_info()per construction through three call chains:get_platform_and_hwsku(),get_port_config(), andget_path_to_port_config_file(). Each call creates aConfigDBConnector(fromswsscommon.swsscommon) that retries connecting to Redis ~3 times with ~7s sleep per retry.The root cause is that
mocked_libs/swsscommon/swsscommon.pywas re-exporting the realConfigDBConnectorandSonicV2Connectorfromswsssdkinstead of providing mock stubs. Sincedevice_info.pyimports these viafrom swsscommon.swsscommon import ConfigDBConnector, SonicV2Connector, and the mocked package is first insys.pathduring tests, replacing them with no-op stubs is sufficient to prevent all Redis connection attempts with no other test changes required.mock_swsscommon.Tablewas also missinggetKeys(), whichTemperatureUpdater.__del__calls during cleanup, causing anAttributeErrorwarning on every test that constructs aTemperatureUpdater.How Has This Been Tested?
Profiled
test_dpu_chassis_thermals(the worst offender) usingcProfile:After fix:
test_dpu_chassis_thermals: ~230s → 0.07sAdditional Information (Optional)
The mock stubs follow the same pattern used in
sonic-chassisd/tests/mock_swsscommon.py.SonicV2Connectoris stubbed alongsideConfigDBConnectorbecausedevice_info.pyimports both in a single statement (from swsscommon.swsscommon import ConfigDBConnector, SonicV2Connector).swsssdkconditionally bypasses its own deprecationImportErrorwhenmockorunittestare already insys.modules— so during pytest the realSonicV2Connectorwould be importable. Stubbing it explicitly removes the dependency on this behavior and ensuresswsssdkis never imported in the test environment.fixes #788