Fix rare timing issue in test_CmisManagerTask_task_worker_decommission #650
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
If the CPU of build server is very fast, testcase
test_CmisManagerTask_task_worker_decommission
might have a chance to fail atsonic-platform-daemons/sonic-xcvrd/tests/test_xcvrd.py
Line 3441 in d555def
The reason is:
update_cmis_state_expiration_time(lport, duration_seconds=0.0)
will setcmis_expired
as current_time (i.e. current_time +0.0
, meaning expired immediately), however there's always aCMIS_EXPIRATION_BUFFER_MS
(2ms
) getting added on top of it.sonic-platform-daemons/sonic-xcvrd/xcvrd/xcvrd.py
Lines 1084 to 1094 in d555def
e.g. if current_time is
01:36:25.528
, callingself.update_cmis_state_expiration_time(lport, 0.0)
, will setcmis_expired
to01:36:25.530
, i.e. 2ms ahead of current time.When testcase is testing
timeout for 'ConfigSuccess'
scenario:sonic-platform-daemons/sonic-xcvrd/xcvrd/xcvrd.py
Lines 1435 to 1441 in d555def
2ms
to run through one while/for loop iteration, so afterself.update_cmis_state_expiration_time(lport, 0.0)
, it costs only two while/loop to becomeis_timer_expired()==True
reachingtimeout for 'ConfigSuccess'
, in total it constantly costs only 17 while/for loop iterations to reach CMIS_STATE_FAILED after retries, in which casetask_stopping_event.is_set = MagicMock(side_effect=[False]*50 + [True]*2)
is more than enough.2ms
, costing more while/for loop iterations to reachtimeout for 'ConfigSuccess'
, which might end up running out oftask_stopping_event.is_set = MagicMock(side_effect=[False]*50 + [True]*2)
too soon , not being able to even reach CMIS_STATE_FAILED, causing testcase assertion failure.In below example, CPU is fast, within 2ms, it's able to run through 5 while/for loop iterations. In other words, it costs 5 while/for loop iterations to reach
timeout for 'ConfigSuccess'
afterself.update_cmis_state_expiration_time(lport, 0.0)
:Motivation and Context
How Has This Been Tested?
Testcase passed
Additional Information (Optional)