Skip to content

Commit

Permalink
Fix intermittent build failure for test_SfpStateUpdateTask_task_run_s…
Browse files Browse the repository at this point in the history
…top (#461)

* Fix intermittent built failure for test_SfpStateUpdateTask_task_run_stop

Signed-off-by: Mihir Patel <patelmi@microsoft.com>

* Modified polling to forever

---------

Signed-off-by: Mihir Patel <patelmi@microsoft.com>
  • Loading branch information
mihirpat1 committed Apr 9, 2024
1 parent d0fd1e1 commit b5f838d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1957,17 +1957,24 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_update_status_hw
assert not task.port_mapping.logical_to_asic
assert mock_update_status_hw.call_count == 1

@patch('xcvrd.xcvrd_utilities.port_event_helper.subscribe_port_config_change', MagicMock(return_value=(None, None)))
def test_SfpStateUpdateTask_task_run_stop(self):
port_mapping = PortMapping()
stop_event = threading.Event()
sfp_error_event = threading.Event()
task = SfpStateUpdateTask(DEFAULT_NAMESPACE, port_mapping, stop_event, sfp_error_event)
task.start()
assert wait_until(5, 1, task.is_alive)
task.raise_exception()
task.join()
assert wait_until(5, 1, lambda: task.is_alive() is False)
def poll_forever(*args, **kwargs):
while True:
time.sleep(1)
# Redefine the XcvrTableHelper function to poll forever so that the task can be stopped by
# raising an exception in between. Also, XcvrTableHelper is the first function to be called after
# starting the task, so having the patch here will avoid the task crashing unexpectedly
# at a different location.
with patch('xcvrd.xcvrd.XcvrTableHelper', new=poll_forever):
port_mapping = PortMapping()
stop_event = threading.Event()
sfp_error_event = threading.Event()
task = SfpStateUpdateTask(DEFAULT_NAMESPACE, port_mapping, stop_event, sfp_error_event)
task.start()
assert wait_until(5, 1, task.is_alive)
task.raise_exception()
task.join()
assert wait_until(5, 1, lambda: task.is_alive() is False)

@patch('xcvrd.xcvrd.XcvrTableHelper', MagicMock())
@patch('xcvrd.xcvrd.post_port_sfp_info_to_db')
Expand Down

0 comments on commit b5f838d

Please sign in to comment.