Skip to content

Commit 9949d80

Browse files
committed
[202305] 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 4fad078 commit 9949d80

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
@@ -1275,17 +1275,24 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_update_status_hw
12751275
assert not task.port_mapping.logical_to_asic
12761276
assert mock_update_status_hw.call_count == 1
12771277

1278-
@patch('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_config_change', MagicMock(return_value=(None, None)))
12791278
def test_SfpStateUpdateTask_task_run_stop(self):
1280-
port_mapping = PortMapping()
1281-
stop_event = threading.Event()
1282-
sfp_error_event = threading.Event()
1283-
task = SfpStateUpdateTask(DEFAULT_NAMESPACE, port_mapping, stop_event, sfp_error_event)
1284-
task.start()
1285-
assert wait_until(5, 1, task.is_alive)
1286-
task.raise_exception()
1287-
task.join()
1288-
assert wait_until(5, 1, lambda: task.is_alive() is False)
1279+
def poll_forever(*args, **kwargs):
1280+
while True:
1281+
time.sleep(1)
1282+
# Redefine the XcvrTableHelper function to poll forever so that the task can be stopped by
1283+
# raising an exception in between. Also, XcvrTableHelper is the first function to be called after
1284+
# starting the task, so having the patch here will avoid the task crashing unexpectedly
1285+
# at a different location.
1286+
with patch('xcvrd.xcvrd.XcvrTableHelper', new=poll_forever):
1287+
port_mapping = PortMapping()
1288+
stop_event = threading.Event()
1289+
sfp_error_event = threading.Event()
1290+
task = SfpStateUpdateTask(DEFAULT_NAMESPACE, port_mapping, stop_event, sfp_error_event)
1291+
task.start()
1292+
assert wait_until(5, 1, task.is_alive)
1293+
task.raise_exception()
1294+
task.join()
1295+
assert wait_until(5, 1, lambda: task.is_alive() is False)
12891296

12901297
@patch('xcvrd.xcvrd.XcvrTableHelper', MagicMock())
12911298
@patch('xcvrd.xcvrd.post_port_sfp_info_to_db')

0 commit comments

Comments
 (0)