Esempio n. 1
0
def GetFirstTimeTestFailuresToRunSwarmingTasks(run_swarming_tasks_input):
    """Gets all first time failed steps and tests in build to run swarming tasks.
  """
    master_name, builder_name, build_number = (
        run_swarming_tasks_input.build_key.GetParts())
    failure_info = run_swarming_tasks_input.heuristic_result.failure_info
    force = run_swarming_tasks_input.force

    if (not failure_info or not failure_info.failed_steps
            or not failure_info.failure_type == failure_type.TEST):
        return {}

    # Gets all the first time failures in the build.
    test_first_failures = test_failure_analysis.GetsFirstFailureAtTestLevel(
        master_name, builder_name, build_number, failure_info, force)

    # Gets the first time failures that have not run swarming tasks.
    new_test_first_failures = {}
    for step_name, tests in test_first_failures.iteritems():
        if NeedANewSwarmingTask(master_name, builder_name, build_number,
                                step_name, force):
            new_test_first_failures[step_name] = tests
    return new_test_first_failures
    def testGetsFirstFailureAtTestLevelForRerun(self):
        master_name = 'm'
        builder_name = 'b'
        build_number = 2
        analysis = WfAnalysis.Create(master_name, builder_name, build_number)
        analysis.failure_result_map = {
            'a_tests': {
                'Unittest1.Subtest1': 'm/b/2'
            }
        }
        analysis.put()

        failure_info = {
            'failed': True,
            'master_name': 'm',
            'builder_name': 'b',
            'build_number': 2,
            'chromium_revision': None,
            'builds': {
                2: {
                    'blame_list': [],
                    'chromium_revision': None
                }
            },
            'failed_steps': {
                'abc_test': {
                    'current_failure': 2,
                    'first_failure': 1,
                    'last_pass': 0,
                    'tests': {
                        'Unittest2.Subtest1': {
                            'current_failure': 2,
                            'first_failure': 2,
                            'last_pass': 1,
                            'base_test_name': 'Unittest2.Subtest1'
                        },
                        'Unittest3.Subtest2': {
                            'current_failure': 2,
                            'first_failure': 1,
                            'last_pass': 0,
                            'base_test_name': 'Unittest3.Subtest2'
                        }
                    },
                    'supported': True
                },
                'a_tests': {
                    'current_failure': 2,
                    'first_failure': 1,
                    'last_pass': 0,
                    'tests': {
                        'Unittest1.Subtest1': {
                            'current_failure': 2,
                            'first_failure': 2,
                            'last_pass': 1,
                            'base_test_name': 'Unittest1.Subtest1'
                        }
                    },
                    'supported': False
                }
            },
            'failure_type': failure_type.TEST
        }

        expected_result = {'abc_test': ['Unittest2.Subtest1']}
        result = (test_failure_analysis.GetsFirstFailureAtTestLevel(
            master_name, builder_name, build_number,
            TestFailureInfo.FromSerializable(failure_info), True))
        self.assertEqual(result, expected_result)
 def testGetsFirstFailureAtTestLevelNoAnalysis(self):
     result = (test_failure_analysis.GetsFirstFailureAtTestLevel(
         'm', 'b', 1, TestFailureInfo.FromSerializable({}), False))
     self.assertEqual(result, {})