1919import tempfile
2020import unittest
2121
22+ import parameterized
23+
2224from clusterfuzz ._internal .bot .tasks .utasks import analyze_task
2325from clusterfuzz ._internal .datastore import data_handler
2426from clusterfuzz ._internal .datastore import data_types
@@ -201,7 +203,8 @@ def setUp(self):
201203 helpers .patch (self , [
202204 'clusterfuzz._internal.bot.tasks.utasks.analyze_task._ERROR_HANDLER.handle' ,
203205 'clusterfuzz._internal.bot.tasks.task_creation.create_tasks' ,
204- 'clusterfuzz._internal.bot.tasks.utasks.analyze_task._add_default_issue_metadata'
206+ 'clusterfuzz._internal.bot.tasks.utasks.analyze_task._add_default_issue_metadata' ,
207+ 'clusterfuzz._internal.datastore.data_handler.update_testcase_comment' ,
205208 ])
206209 self .testcase = test_utils .create_generic_testcase ()
207210 self .testcase_metadata = data_types .TestcaseUploadMetadata (
@@ -245,9 +248,30 @@ def test_processed_testcase_flow(self):
245248 self .assertTrue (self .mock ._add_default_issue_metadata .called ) # pylint: disable=protected-access
246249 self .assertTrue (self .mock .create_tasks .called )
247250
251+ @parameterized .parameterized .expand ([
252+ (False , 'Testcase crashed in 13.0 of 17.0 seconds (r123)' ),
253+ (True , 'Testcase crashed in 13.0 of 17.0 seconds (r123), but is flaky' ),
254+ ])
255+ def test_crash_time_test_timeout_in_log_message (self , is_flaky ,
256+ expected_message ):
257+ """Test log message of crashed analyze tasks."""
258+ analyze_task_output = uworker_msg_pb2 .AnalyzeTaskOutput (
259+ crash_revision = 123 , one_time_crasher_flag = is_flaky )
260+ uworker_output = uworker_msg_pb2 .Output (
261+ uworker_input = self .uworker_input ,
262+ analyze_task_output = analyze_task_output ,
263+ crash_time = 13 ,
264+ test_timeout = 17 ,
265+ issue_metadata = '{}' )
266+
267+ analyze_task .utask_postprocess (uworker_output )
268+ testcase = data_handler .get_testcase_by_id (self .testcase .key .id ())
269+ self .mock .update_testcase_comment .assert_called_with (
270+ testcase , 'finished' , expected_message )
271+
248272
249273@test_utils .with_cloud_emulators ('datastore' )
250- class HandleEventEmitionNonCrashTest (unittest .TestCase ):
274+ class HandleEventEmissionNonCrashTest (unittest .TestCase ):
251275 """Tests for handle_noncrash."""
252276
253277 def setUp (self ):
@@ -268,7 +292,7 @@ def setUp(self):
268292 testcase_id = str (self .testcase .key .id ()))
269293 self .uworker_output = uworker_msg_pb2 .Output (uworker_input = uworker_input )
270294
271- def test_event_emition_handle_noncrash_first_attempt (self ):
295+ def test_event_emission_handle_noncrash_first_attempt (self ):
272296 """Test that a non-crashing testcase is retried on the first attempt."""
273297 self .mock .is_first_attempt_for_task .return_value = True
274298 analyze_task .handle_noncrash (self .uworker_output )
@@ -278,7 +302,7 @@ def test_event_emition_handle_noncrash_first_attempt(self):
278302 rejection_reason = events .RejectionReason .
279303 ANALYZE_FLAKE_ON_FIRST_ATTEMPT ))
280304
281- def test_event_emition_handle_noncrash_second_attempt (self ):
305+ def test_event_emission_handle_noncrash_second_attempt (self ):
282306 """Test that a non-crashing testcase is marked invalid after the second attempt."""
283307 self .mock .is_first_attempt_for_task .return_value = False
284308 analyze_task .handle_noncrash (self .uworker_output )
0 commit comments