Skip to content

Commit ec5b3c3

Browse files
committed
[202311] Fix intermittent build failure for test_SfpStateUpdateTask_task_run_stop (sonic-net#461)
* Fix intermittent built failure for test_SfpStateUpdateTask_task_run_stop Signed-off-by: Mihir Patel <[email protected]> * Modified polling to forever --------- Signed-off-by: Mihir Patel <[email protected]>
1 parent fa46abb commit ec5b3c3

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

sonic-xcvrd/tests/test_xcvrd.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -1552,17 +1552,24 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_update_status_hw
15521552
assert not task.port_mapping.logical_to_asic
15531553
assert mock_update_status_hw.call_count == 1
15541554

1555-
@patch('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_config_change', MagicMock(return_value=(None, None)))
15561555
def test_SfpStateUpdateTask_task_run_stop(self):
1557-
port_mapping = PortMapping()
1558-
stop_event = threading.Event()
1559-
sfp_error_event = threading.Event()
1560-
task = SfpStateUpdateTask(DEFAULT_NAMESPACE, port_mapping, stop_event, sfp_error_event)
1561-
task.start()
1562-
assert wait_until(5, 1, task.is_alive)
1563-
task.raise_exception()
1564-
task.join()
1565-
assert wait_until(5, 1, lambda: task.is_alive() is False)
1556+
def poll_forever(*args, **kwargs):
1557+
while True:
1558+
time.sleep(1)
1559+
# Redefine the XcvrTableHelper function to poll forever so that the task can be stopped by
1560+
# raising an exception in between. Also, XcvrTableHelper is the first function to be called after
1561+
# starting the task, so having the patch here will avoid the task crashing unexpectedly
1562+
# at a different location.
1563+
with patch('xcvrd.xcvrd.XcvrTableHelper', new=poll_forever):
1564+
port_mapping = PortMapping()
1565+
stop_event = threading.Event()
1566+
sfp_error_event = threading.Event()
1567+
task = SfpStateUpdateTask(DEFAULT_NAMESPACE, port_mapping, stop_event, sfp_error_event)
1568+
task.start()
1569+
assert wait_until(5, 1, task.is_alive)
1570+
task.raise_exception()
1571+
task.join()
1572+
assert wait_until(5, 1, lambda: task.is_alive() is False)
15661573

15671574
@patch('xcvrd.xcvrd.XcvrTableHelper', MagicMock())
15681575
@patch('xcvrd.xcvrd.post_port_sfp_info_to_db')

0 commit comments

Comments
 (0)