| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from collections import defaultdict | 5 from collections import defaultdict |
| 6 import logging | 6 import logging |
| 7 | 7 |
| 8 from common import appengine_util | 8 from common import appengine_util |
| 9 from common import constants | 9 from common import constants |
| 10 from common.pipeline_wrapper import BasePipeline | 10 from common.pipeline_wrapper import BasePipeline |
| 11 from common.pipeline_wrapper import pipeline | |
| 12 from model import analysis_status | 11 from model import analysis_status |
| 13 from model.wf_try_job import WfTryJob | 12 from model.wf_try_job import WfTryJob |
| 14 from waterfall import try_job_pipeline | 13 from waterfall import try_job_pipeline |
| 15 from waterfall.try_job_type import TryJobType | 14 from waterfall.try_job_type import TryJobType |
| 16 | 15 |
| 17 | 16 |
| 18 def _GetReliableTargetedTests(targeted_tests, classified_tests_by_step): | 17 def _GetReliableTargetedTests(targeted_tests, classified_tests_by_step, |
| 18 force_try_job=False): |
| 19 """Returns a dict containing a list of reliable tests for each failed step.""" | 19 """Returns a dict containing a list of reliable tests for each failed step.""" |
| 20 reliable_tests = defaultdict(list) | 20 reliable_tests = defaultdict(list) |
| 21 for step_name, tests in targeted_tests.iteritems(): | 21 for step_name, tests in targeted_tests.iteritems(): |
| 22 # Skips non-swarming steps to avoid false positives. | 22 # Skips non-swarming steps to avoid false positives. |
| 23 # TODO(chanli): It is very unlikely for some non-swarming steps to be flaky. | 23 # TODO(chanli): It is very unlikely for some non-swarming steps to be flaky. |
| 24 # Need to identify those steps and add them to a whitelist. | 24 # Need to identify those steps and add them to a whitelist. |
| 25 if step_name in classified_tests_by_step: # Swarming step. | 25 if step_name in classified_tests_by_step: # Swarming step. |
| 26 step_name_no_platform = classified_tests_by_step[step_name][0] | 26 step_name_no_platform = classified_tests_by_step[step_name][0] |
| 27 classified_tests = classified_tests_by_step[step_name][1] | 27 classified_tests = classified_tests_by_step[step_name][1] |
| 28 | 28 |
| 29 for test in tests: | 29 for test in tests: |
| 30 # If the step is swarming but there is no result for it, it's highly | 30 # If the step is swarming but there is no result for it, it's highly |
| 31 # likely that there is some error with the task. | 31 # likely that there is some error with the task. |
| 32 # Thus skip this step for no insights from task to avoid false positive. | 32 # Thus skip this step for no insights from task to avoid false positive. |
| 33 if (test in classified_tests.get('reliable_tests', [])): | 33 if test in classified_tests.get('reliable_tests', []): |
| 34 reliable_tests[step_name_no_platform].append(test) | 34 reliable_tests[step_name_no_platform].append(test) |
| 35 elif force_try_job: |
| 36 # Try jobs were forced to be rerun regardless of being non-swarming. |
| 37 reliable_tests[step_name] = [] |
| 35 return reliable_tests | 38 return reliable_tests |
| 36 | 39 |
| 37 | 40 |
| 38 class RunTryJobForReliableFailurePipeline(BasePipeline): | 41 class RunTryJobForReliableFailurePipeline(BasePipeline): |
| 39 """A pipeline to trigger try job for reliable failures. | 42 """A pipeline to trigger try job for reliable failures. |
| 40 | 43 |
| 41 Processes result from SwarmingTaskPipeline and start TryJobPipeline if there | 44 Processes result from SwarmingTaskPipeline and start TryJobPipeline if there |
| 42 are reliable test failures. | 45 are reliable test failures. |
| 43 Starts TryJobPipeline directly for compile failure. | 46 Starts TryJobPipeline directly for compile failure. |
| 44 """ | 47 """ |
| 45 | 48 |
| 46 # Arguments number differs from overridden method - pylint: disable=W0221 | 49 # Arguments number differs from overridden method - pylint: disable=W0221 |
| 47 def run( | 50 def run( |
| 48 self, master_name, builder_name, build_number, good_revision, | 51 self, master_name, builder_name, build_number, good_revision, |
| 49 bad_revision, blame_list, try_job_type, compile_targets, targeted_tests, | 52 bad_revision, blame_list, try_job_type, compile_targets, targeted_tests, |
| 50 suspected_revisions, *classified_tests_by_step): | 53 suspected_revisions, force_try_job, *classified_tests_by_step): |
| 51 """ | 54 """ |
| 52 Args: | 55 Args: |
| 53 master_name (str): Name of the master. | 56 master_name (str): Name of the master. |
| 54 builder_name (str): Name of the builder. | 57 builder_name (str): Name of the builder. |
| 55 build_number (int): Number of the current failed build. | 58 build_number (int): Number of the current failed build. |
| 56 good_revision (str): Revision of last green build. | 59 good_revision (str): Revision of last green build. |
| 57 bad_revision (str): Revision of current build. | 60 bad_revision (str): Revision of current build. |
| 58 blame_list (list): A list of revisions between above 2 revisions. | 61 blame_list (list): A list of revisions between above 2 revisions. |
| 59 try_job_type (str): Type of the try job ('compile' or 'test'). | 62 try_job_type (str): Type of the try job ('compile' or 'test'). |
| 60 compile_targets (list): A list of failed targets for compile failure. | 63 compile_targets (list): A list of failed targets for compile failure. |
| 61 targeted_tests (dict): A dict of failed tests for test failure. | 64 targeted_tests (dict): A dict of failed tests for test failure. |
| 62 suspected_revisions (list): Suspected revisions for a compile failure. | 65 suspected_revisions (list): Suspected revisions for a compile failure. |
| 66 force_try_job (bool): Whether or not a try job should be run |
| 67 regardless of non swarming-steps. |
| 63 *classified_tests_by_step (list): A list of tuples of step_name and | 68 *classified_tests_by_step (list): A list of tuples of step_name and |
| 64 classified_tests. The format is like: | 69 classified_tests. The format is like: |
| 65 [('step1', {'flaky_tests': ['test1', ..], ..}), ..] | 70 [('step1', {'flaky_tests': ['test1', ..], ..}), |
| 71 ..] |
| 66 """ | 72 """ |
| 67 if try_job_type == TryJobType.TEST: | 73 if try_job_type == TryJobType.TEST: |
| 68 targeted_tests = _GetReliableTargetedTests( | 74 targeted_tests = _GetReliableTargetedTests( |
| 69 targeted_tests, dict(classified_tests_by_step)) | 75 targeted_tests, dict(classified_tests_by_step), force_try_job) |
| 76 |
| 70 if targeted_tests or try_job_type == TryJobType.COMPILE: | 77 if targeted_tests or try_job_type == TryJobType.COMPILE: |
| 71 new_try_job_pipeline = try_job_pipeline.TryJobPipeline( | 78 new_try_job_pipeline = try_job_pipeline.TryJobPipeline( |
| 72 master_name, builder_name, build_number, good_revision, | 79 master_name, builder_name, build_number, good_revision, |
| 73 bad_revision, blame_list, try_job_type, compile_targets, | 80 bad_revision, blame_list, try_job_type, compile_targets, |
| 74 targeted_tests, suspected_revisions) | 81 targeted_tests, suspected_revisions) |
| 75 | 82 |
| 76 new_try_job_pipeline.target = appengine_util.GetTargetNameForModule( | 83 new_try_job_pipeline.target = appengine_util.GetTargetNameForModule( |
| 77 constants.WATERFALL_BACKEND) | 84 constants.WATERFALL_BACKEND) |
| 78 new_try_job_pipeline.start(queue_name=constants.WATERFALL_TRY_JOB_QUEUE) | 85 new_try_job_pipeline.start(queue_name=constants.WATERFALL_TRY_JOB_QUEUE) |
| 79 logging.info('Try-job was scheduled for build %s, %s, %s: %s', | 86 logging.info('Try-job was scheduled for build %s, %s, %s: %s', |
| 80 master_name, builder_name, build_number, | 87 master_name, builder_name, build_number, |
| 81 new_try_job_pipeline.pipeline_status_path) | 88 new_try_job_pipeline.pipeline_status_path) |
| 82 else: # pragma: no cover | 89 else: # pragma: no cover |
| 83 # No need to start try job, mark it as skipped. | 90 # No need to start try job, mark it as skipped. |
| 84 try_job_result = WfTryJob.Get( | 91 try_job_result = WfTryJob.Get( |
| 85 master_name, builder_name, build_number) | 92 master_name, builder_name, build_number) |
| 86 if try_job_result: | 93 if try_job_result: |
| 87 try_job_result.status = analysis_status.SKIPPED | 94 try_job_result.status = analysis_status.SKIPPED |
| 88 try_job_result.put() | 95 try_job_result.put() |
| 89 return | 96 return |
| OLD | NEW |