@@ -59,7 +59,8 @@ def setUp(self):
5959 self .test_port = self .server .add_insecure_port ('[::]:0' )
6060 self .server .start ()
6161 self .url = 'localhost:%s' % self .test_port
62- self .fn_status_handler = FnApiWorkerStatusHandler (self .url )
62+ self .fn_status_handler = FnApiWorkerStatusHandler (
63+ self .url , element_processing_timeout_minutes = 10 )
6364
6465 def tearDown (self ):
6566 self .server .stop (5 )
@@ -89,42 +90,48 @@ def test_generate_error(self, mock_method):
8990 def test_log_lull_in_bundle_processor (self ):
9091 def get_state_sampler_info_for_lull (lull_duration_s ):
9192 return "bundle-id" , statesampler .StateSamplerInfo (
92- CounterName ('progress-msecs' , 'stage_name' , 'step_name' ),
93- 1 ,
94- lull_duration_s * 1e9 ,
95- threading .current_thread ())
93+ CounterName ('progress-msecs' , 'stage_name' , 'step_name' ),
94+ 1 ,
95+ lull_duration_s * 1e9 ,
96+ threading .current_thread ())
9697
9798 now = time .time ()
9899 with mock .patch ('logging.Logger.warning' ) as warn_mock :
99- with mock .patch ('time.time' ) as time_mock :
100- time_mock .return_value = now
101- bundle_id , sampler_info = get_state_sampler_info_for_lull (21 * 60 )
102- self .fn_status_handler ._log_lull_sampler_info (sampler_info , bundle_id )
103-
104- bundle_id_template = warn_mock .call_args [0 ][1 ]
105- step_name_template = warn_mock .call_args [0 ][2 ]
106- processing_template = warn_mock .call_args [0 ][3 ]
107- traceback = warn_mock .call_args = warn_mock .call_args [0 ][4 ]
108-
109- self .assertIn ('bundle-id' , bundle_id_template )
110- self .assertIn ('step_name' , step_name_template )
111- self .assertEqual (21 * 60 , processing_template )
112- self .assertIn ('test_log_lull_in_bundle_processor' , traceback )
113-
114- with mock .patch ('time.time' ) as time_mock :
115- time_mock .return_value = now + 6 * 60 # 6 minutes
116- bundle_id , sampler_info = get_state_sampler_info_for_lull (21 * 60 )
117- self .fn_status_handler ._log_lull_sampler_info (sampler_info , bundle_id )
118-
119- with mock .patch ('time.time' ) as time_mock :
120- time_mock .return_value = now + 21 * 60 # 21 minutes
121- bundle_id , sampler_info = get_state_sampler_info_for_lull (10 * 60 )
122- self .fn_status_handler ._log_lull_sampler_info (sampler_info , bundle_id )
123-
124- with mock .patch ('time.time' ) as time_mock :
125- time_mock .return_value = now + 42 * 60 # 21 minutes after previous one
126- bundle_id , sampler_info = get_state_sampler_info_for_lull (21 * 60 )
127- self .fn_status_handler ._log_lull_sampler_info (sampler_info , bundle_id )
100+ with mock .patch (
101+ 'apache_beam.runners.worker.sdk_worker_main.terminate_sdk_harness'
102+ ) as flush_mock :
103+ with mock .patch ('time.time' ) as time_mock :
104+ time_mock .return_value = now
105+ bundle_id , sampler_info = get_state_sampler_info_for_lull (21 * 60 )
106+ self .fn_status_handler ._log_lull_sampler_info (sampler_info , bundle_id )
107+ bundle_id_template = warn_mock .call_args [0 ][1 ]
108+ step_name_template = warn_mock .call_args [0 ][2 ]
109+ processing_template = warn_mock .call_args [0 ][3 ]
110+ traceback = warn_mock .call_args = warn_mock .call_args [0 ][4 ]
111+
112+ self .assertIn ('bundle-id' , bundle_id_template )
113+ self .assertIn ('step_name' , step_name_template )
114+ self .assertEqual (21 * 60 , processing_template )
115+ self .assertIn ('test_log_lull_in_bundle_processor' , traceback )
116+ flush_mock .assert_called_once ()
117+
118+ with mock .patch ('time.time' ) as time_mock :
119+ time_mock .return_value = now + 6 * 60 # 6 minutes
120+ bundle_id , sampler_info = get_state_sampler_info_for_lull (21 * 60 )
121+ self .fn_status_handler ._log_lull_sampler_info (sampler_info , bundle_id )
122+ self .assertEqual (flush_mock .call_count , 2 )
123+
124+ with mock .patch ('time.time' ) as time_mock :
125+ time_mock .return_value = now + 21 * 60 # 21 minutes
126+ bundle_id , sampler_info = get_state_sampler_info_for_lull (10 * 60 )
127+ self .fn_status_handler ._log_lull_sampler_info (sampler_info , bundle_id )
128+ self .assertEqual (flush_mock .call_count , 2 )
129+
130+ with mock .patch ('time.time' ) as time_mock :
131+ time_mock .return_value = now + 42 * 60 # 42 minutes
132+ bundle_id , sampler_info = get_state_sampler_info_for_lull (11 * 60 )
133+ self .fn_status_handler ._log_lull_sampler_info (sampler_info , bundle_id )
134+ self .assertEqual (flush_mock .call_count , 3 )
128135
129136
130137class HeapDumpTest (unittest .TestCase ):
0 commit comments