| 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 import logging | 5 import logging |
| 6 | 6 |
| 7 from common.pipeline_wrapper import BasePipeline | 7 from common.pipeline_wrapper import BasePipeline |
| 8 from waterfall.process_swarming_task_result_pipeline import ( | 8 from waterfall.process_swarming_task_result_pipeline import ( |
| 9 ProcessSwarmingTaskResultPipeline) | 9 ProcessSwarmingTaskResultPipeline) |
| 10 from waterfall.run_try_job_for_reliable_failure_pipeline import ( | 10 from waterfall.run_try_job_for_reliable_failure_pipeline import ( |
| 11 RunTryJobForReliableFailurePipeline) | 11 RunTryJobForReliableFailurePipeline) |
| 12 from waterfall.trigger_swarming_task_pipeline import TriggerSwarmingTaskPipeline | 12 from waterfall.trigger_swarming_task_pipeline import TriggerSwarmingTaskPipeline |
| 13 from waterfall.try_job_type import TryJobType | 13 from waterfall.try_job_type import TryJobType |
| 14 | 14 |
| 15 | 15 |
| 16 _PRE_TEST_PREFIX = 'PRE_' |
| 17 |
| 18 |
| 19 def _RemoveAnyPrefixes(tests): |
| 20 """Remove prefixes from test names. |
| 21 |
| 22 Args: |
| 23 tests (list): A list of tests, eg: ['suite1.PRE_test1', 'suite2.test2']. |
| 24 |
| 25 Returns: |
| 26 base_tests (list): A list of base tests, eg: |
| 27 ['suite1.test1', 'suite2.test2']. |
| 28 """ |
| 29 base_tests = [] |
| 30 for test in tests: |
| 31 test_name_start = test.find('.') if test.find('.') > -1 else 0 |
| 32 test_suite = test[ : test_name_start] |
| 33 test_name = test[test_name_start + 1 : ] |
| 34 pre_position = test_name.find(_PRE_TEST_PREFIX) |
| 35 while pre_position == 0: |
| 36 test_name = test_name[len(_PRE_TEST_PREFIX):] |
| 37 pre_position = test_name.find(_PRE_TEST_PREFIX) |
| 38 base_tests.append(test_suite + '.' + test_name) |
| 39 return base_tests |
| 40 |
| 41 |
| 16 class SwarmingTasksToTryJobPipeline(BasePipeline): | 42 class SwarmingTasksToTryJobPipeline(BasePipeline): |
| 17 """Root Pipeline to start swarming tasks and possible try job on the build.""" | 43 """Root Pipeline to start swarming tasks and possible try job on the build.""" |
| 18 | 44 |
| 19 # Arguments number differs from overridden method - pylint: disable=W0221 | 45 # Arguments number differs from overridden method - pylint: disable=W0221 |
| 20 def run( | 46 def run( |
| 21 self, master_name, builder_name, build_number, good_revision, | 47 self, master_name, builder_name, build_number, good_revision, |
| 22 bad_revision, blame_list, try_job_type, compile_targets=None, | 48 bad_revision, blame_list, try_job_type, compile_targets=None, |
| 23 targeted_tests=None, suspected_cls=None): | 49 targeted_tests=None, suspected_cls=None): |
| 24 | 50 |
| 25 # A list contains tuples of step_names and classified_tests from | 51 # A list contains tuples of step_names and classified_tests from |
| 26 # ProcessSwarmingTaskResultPipeline. | 52 # ProcessSwarmingTaskResultPipeline. |
| 27 # The format would be [('step1', {'flaky_tests': ['test1', ..], ..}), ..] | 53 # The format would be [('step1', {'flaky_tests': ['test1', ..], ..}), ..] |
| 28 classified_tests_by_step = [] | 54 classified_tests_by_step = [] |
| 55 targeted_base_tests = {} |
| 29 | 56 |
| 30 if try_job_type == TryJobType.TEST: | 57 if try_job_type == TryJobType.TEST: |
| 31 for step_name, tests in targeted_tests.iteritems(): | 58 for step_name, tests in targeted_tests.iteritems(): |
| 59 base_tests = _RemoveAnyPrefixes(tests) |
| 60 targeted_base_tests[step_name] = base_tests |
| 61 |
| 32 if not tests: # Skip non-swarming tests. | 62 if not tests: # Skip non-swarming tests. |
| 33 continue | 63 continue |
| 64 # Triggers swarming task for the base_tests. |
| 34 task_id = yield TriggerSwarmingTaskPipeline( | 65 task_id = yield TriggerSwarmingTaskPipeline( |
| 35 master_name, builder_name, build_number, step_name, tests) | 66 master_name, builder_name, build_number, step_name, base_tests) |
| 36 step_future = yield ProcessSwarmingTaskResultPipeline( | 67 step_future = yield ProcessSwarmingTaskResultPipeline( |
| 37 master_name, builder_name, build_number, step_name, task_id) | 68 master_name, builder_name, build_number, step_name, task_id) |
| 38 logging_str = ( | 69 logging_str = ( |
| 39 'Swarming task was scheduled for build %s/%s/%s step %s') % ( | 70 'Swarming task was scheduled for build %s/%s/%s step %s') % ( |
| 40 master_name, builder_name, build_number, step_name) | 71 master_name, builder_name, build_number, step_name) |
| 41 logging.info(logging_str) | 72 logging.info(logging_str) |
| 42 classified_tests_by_step.append(step_future) | 73 classified_tests_by_step.append(step_future) |
| 43 | 74 |
| 44 # Waits until classified_tests_by_step are ready. | 75 # Waits until classified_tests_by_step are ready. |
| 45 yield RunTryJobForReliableFailurePipeline( | 76 yield RunTryJobForReliableFailurePipeline( |
| 46 master_name, builder_name, build_number, good_revision, | 77 master_name, builder_name, build_number, good_revision, |
| 47 bad_revision, blame_list, try_job_type, compile_targets, targeted_tests, | 78 bad_revision, blame_list, try_job_type, compile_targets, |
| 48 suspected_cls, *classified_tests_by_step) | 79 targeted_base_tests, suspected_cls, *classified_tests_by_step) |
| OLD | NEW |