|
19 | 19 | import unittest |
20 | 20 |
|
21 | 21 | from clusterfuzz._internal.bot.tasks.utasks import analyze_task |
| 22 | +from clusterfuzz._internal.datastore import data_handler |
22 | 23 | from clusterfuzz._internal.datastore import data_types |
| 24 | +from clusterfuzz._internal.protos import uworker_msg_pb2 |
23 | 25 | from clusterfuzz._internal.tests.test_libs import helpers |
24 | 26 | from clusterfuzz._internal.tests.test_libs import test_utils |
25 | 27 | from clusterfuzz._internal.tests.test_libs import utask_helpers |
@@ -186,3 +188,57 @@ def test_analyze_reproducible(self): |
186 | 188 | # testcase = self.testcase.key.get(use_cache=False, use_memcache=False) |
187 | 189 | # self.assertTrue(testcase.status, 'Processed') |
188 | 190 | # self.assertIn('SCARINESS', testcase.crash_stacktrace) |
| 191 | + |
| 192 | + |
| 193 | +@test_utils.with_cloud_emulators('datastore') |
| 194 | +class UTaskPostprocessTest(unittest.TestCase): |
| 195 | + """Tests for analyze_task.utask_postprocess.""" |
| 196 | + |
| 197 | + def setUp(self): |
| 198 | + helpers.patch_environ(self) |
| 199 | + helpers.patch(self, [ |
| 200 | + 'clusterfuzz._internal.bot.tasks.utasks.analyze_task._ERROR_HANDLER.handle', |
| 201 | + 'clusterfuzz._internal.bot.tasks.task_creation.create_tasks', |
| 202 | + 'clusterfuzz._internal.bot.tasks.utasks.analyze_task._add_default_issue_metadata' |
| 203 | + ]) |
| 204 | + self.testcase = test_utils.create_generic_testcase() |
| 205 | + self.testcase_metadata = data_types.TestcaseUploadMetadata( |
| 206 | + testcase_id=self.testcase.key.id()) |
| 207 | + self.testcase_metadata.put() |
| 208 | + self.uworker_input = uworker_msg_pb2.Input( |
| 209 | + testcase_id=str(self.testcase.key.id())) |
| 210 | + |
| 211 | + def test_error_handling_called_on_error(self): |
| 212 | + """Checks that an output with an error is handled properly.""" |
| 213 | + uworker_output = uworker_msg_pb2.Output( |
| 214 | + uworker_input=self.uworker_input, |
| 215 | + error_type=uworker_msg_pb2.ErrorType.UNHANDLED) |
| 216 | + analyze_task.utask_postprocess(uworker_output) |
| 217 | + self.assertTrue(self.mock.handle.called) |
| 218 | + |
| 219 | + def test_processed_testcase_flow(self): |
| 220 | + """Tests utask_postprocess behaviour when there is a crash on latest revision.""" |
| 221 | + analyze_task_output = uworker_msg_pb2.AnalyzeTaskOutput( |
| 222 | + crash_revision=123, |
| 223 | + absolute_path='absolute_path', |
| 224 | + minimized_arguments='minimized_arguments') |
| 225 | + uworker_output = uworker_msg_pb2.Output( |
| 226 | + uworker_input=self.uworker_input, |
| 227 | + analyze_task_output=analyze_task_output, |
| 228 | + issue_metadata='{}') |
| 229 | + |
| 230 | + testcase = data_handler.get_testcase_by_id( |
| 231 | + uworker_output.uworker_input.testcase_id) |
| 232 | + self.assertEqual(testcase.crash_revision, 1) |
| 233 | + self.assertEqual(testcase.absolute_path, '/a/b/c/test.html') |
| 234 | + self.assertEqual(testcase.minimized_arguments, '') |
| 235 | + analyze_task.utask_postprocess(uworker_output) |
| 236 | + testcase = data_handler.get_testcase_by_id( |
| 237 | + uworker_output.uworker_input.testcase_id) |
| 238 | + self.assertFalse(self.mock.handle.called) |
| 239 | + # Make sure the testcase is updated with analyze_task output |
| 240 | + self.assertEqual(testcase.crash_revision, 123) |
| 241 | + self.assertEqual(testcase.absolute_path, 'absolute_path') |
| 242 | + self.assertEqual(testcase.minimized_arguments, 'minimized_arguments') |
| 243 | + self.assertTrue(self.mock._add_default_issue_metadata.called) # pylint: disable=protected-access |
| 244 | + self.assertTrue(self.mock.create_tasks.called) |
0 commit comments