[202311] Fix intermittent build failure for test_SfpStateUpdateTask_task_run_stop #464
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.
Cherry-pick for #461
MSFT ADO - 24271303
Description
An intermittent build failure is seen for the test_SfpStateUpdateTask_task_run_stop unit-test with the below backtrace. We have observed more than one type of backtrace so far (details are mentioned in the issues mentioned below).
Consistent way to fail the test
Add at least 1s sleep in between the below lines
sonic-platform-daemons/sonic-xcvrd/tests/test_xcvrd.py
Lines 1966 to 1967 in d0fd1e1
Motivation and Context
fixes #369, fixes #370, fixes #382
Intention of the testcase
The test case tests a scenario wherein while SfpStateUpdateTask thread is busy polling for few seconds, its parent process (xcvrd in an ideal case) generates an exception to stop the SfpStateUpdateTask thread in the middle of polling.
RCA for current failure
Since
test_SfpStateUpdateTask_task_run_stop
does not have all the underlying functions of SfpStateUpdateTask.task_worker mocked, there is a probability of SfpStateUpdateTask thread exiting early which will thereby causeassert wait_until(5, 1, task.is_alive)
to fail based on the place at which SfpStateUpdateTask thread crashes.Fix details
Modified the implementation of
XcvrTableHelper
function to have a busy polling to ensure that SfpStateUpdateTask thread does not quit before thetest_SfpStateUpdateTask_task_run_stop
testcase raises an exception.Also, this approach will ensure that if any new function calls are being added in SfpStateUpdateTask.task_worker, they will not needed to be mocked in SfpStateUpdateTask.task_worker since
XcvrTableHelper
is the first function called in SfpStateUpdateTask.task_worker.How Has This Been Tested?
Ran the test multiple times to ensure that the testcases passes.
Also, added a 3s sleep in between the below lines and ensured that the testcases was passing consistently.
sonic-platform-daemons/sonic-xcvrd/tests/test_xcvrd.py
Lines 1966 to 1967 in d0fd1e1
Additional Information (Optional)