@@ -1275,17 +1275,24 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_update_status_hw
1275
1275
assert not task .port_mapping .logical_to_asic
1276
1276
assert mock_update_status_hw .call_count == 1
1277
1277
1278
- @patch ('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_config_change' , MagicMock (return_value = (None , None )))
1279
1278
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 )
1289
1296
1290
1297
@patch ('xcvrd.xcvrd.XcvrTableHelper' , MagicMock ())
1291
1298
@patch ('xcvrd.xcvrd.post_port_sfp_info_to_db' )
0 commit comments