@@ -1552,17 +1552,24 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_update_status_hw
1552
1552
assert not task .port_mapping .logical_to_asic
1553
1553
assert mock_update_status_hw .call_count == 1
1554
1554
1555
- @patch ('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_config_change' , MagicMock (return_value = (None , None )))
1556
1555
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 )
1566
1573
1567
1574
@patch ('xcvrd.xcvrd.XcvrTableHelper' , MagicMock ())
1568
1575
@patch ('xcvrd.xcvrd.post_port_sfp_info_to_db' )
0 commit comments