def testYieldSubdir(self): """Make sure subdir are properly set for test and non-test status.""" job_tag = '0-owner/172.33.44.55' job_name = 'broken_infra_job' job = FakeJob(0, [ FakeStatus('ERROR', 'SERVER_JOB', 'server error', subdir='---', job_tag=job_tag), FakeStatus('GOOD', 'T0', '', subdir='T0.subdir', job_tag=job_tag) ], parent_job_id=54321) for status in job.statuses: status.entry['job'] = {'name': job_name} self.expect_yield_job_entries(job) self.mox.ReplayAll() results = list(job_status._yield_job_results(self.afe, self.tko, job)) for i in range(len(results)): result = results[i] if result.test_name.endswith('SERVER_JOB'): expected_name = '%s_%s' % (job_name, job.statuses[i].test_name) expected_subdir = job_tag else: expected_name = job.statuses[i].test_name expected_subdir = os.path.join(job_tag, job.statuses[i].subdir) self.assertEqual(results[i].test_name, expected_name) self.assertEqual(results[i].subdir, expected_subdir)
def testWaitForChildResults(self): """Should gather status and return records for job summaries.""" parent_job_id = 54321 jobs = [ FakeJob( 0, [FakeStatus('GOOD', 'T0', ''), FakeStatus('GOOD', 'T1', '')], parent_job_id=parent_job_id), FakeJob(1, [ FakeStatus('ERROR', 'T0', 'err', False), FakeStatus('GOOD', 'T1', '') ], parent_job_id=parent_job_id), FakeJob(2, [FakeStatus('TEST_NA', 'T0', 'no')], parent_job_id=parent_job_id), FakeJob(3, [FakeStatus('FAIL', 'T0', 'broken')], parent_job_id=parent_job_id), FakeJob(4, [ FakeStatus('ERROR', 'SERVER_JOB', 'server error'), FakeStatus('GOOD', 'T0', '') ], parent_job_id=parent_job_id), ] # TODO: Write a better test for the case where we yield # results for aborts vs cannot yield results because of # a premature abort. Currently almost all client aborts # have been converted to failures and when aborts do happen # they result in server job failures for which we always # want results. #FakeJob(5, [FakeStatus('ERROR', 'T0', 'gah', True)], # parent_job_id=parent_job_id), # The next job shouldn't be recorded in the results. #FakeJob(6, [FakeStatus('GOOD', 'SERVER_JOB', '')], # parent_job_id=12345)] for status in jobs[4].statuses: status.entry['job'] = {'name': 'broken_infra_job'} # Expect one call to get a list of all child jobs. self.afe.get_jobs(parent_job_id=parent_job_id).AndReturn(jobs[:6]) job_id_set = set([job.id for job in jobs]) yield_values = [[jobs[1]], [jobs[0], jobs[2]], jobs[3:6]] self.mox.StubOutWithMock(time, 'sleep') for yield_this in yield_values: self.afe.get_jobs(id__in=list(job_id_set), finished=True).AndReturn(yield_this) for job in yield_this: self.expect_yield_job_entries(job) job_id_set.remove(job.id) time.sleep(mox.IgnoreArg()) self.mox.ReplayAll() results = [ result for result in job_status.wait_for_child_results( self.afe, self.tko, parent_job_id) ] for job in jobs[:6]: # the 'GOOD' SERVER_JOB shouldn't be there. for status in job.statuses: self.assertTrue(True in map(status.equals_record, results))
def testGatherPerHostResults(self): """Should gather per host results.""" # For the 0th job, the 1st entry is more bad/specific. # For all the others, it's the 0th that we expect. jobs = [ FakeJob(0, [ FakeStatus('FAIL', 'T0', '', hostname='h0'), FakeStatus('FAIL', 'T1', 'bad', hostname='h0') ]), FakeJob(1, [ FakeStatus('ERROR', 'T0', 'err', False, 'h1'), FakeStatus('GOOD', 'T1', '', hostname='h1') ]), FakeJob(2, [FakeStatus('TEST_NA', 'T0', 'no', hostname='h2')]), FakeJob(3, [FakeStatus('FAIL', 'T0', 'broken', hostname='h3')]), FakeJob(4, [FakeStatus('ERROR', 'T0', 'gah', True, 'h4')]), FakeJob(5, [FakeStatus('GOOD', 'T0', 'Yay', hostname='h5')]) ] # Method under test returns status available right now. for job in jobs: entries = map(lambda s: s.entry, job.statuses) self.afe.run('get_host_queue_entries', job=job.id).AndReturn(entries) self.tko.get_job_test_statuses_from_db(job.id).AndReturn( job.statuses) self.mox.ReplayAll() results = job_status.gather_per_host_results(self.afe, self.tko, jobs).values() for status in [jobs[0].statuses[1] ] + [j.statuses[0] for j in jobs[1:]]: self.assertTrue( True in map(status.equals_hostname_record, results))
def testWaitForResults(self): """Should gather status and return records for job summaries.""" jobs = [ FakeJob( 0, [FakeStatus('GOOD', 'T0', ''), FakeStatus('GOOD', 'T1', '')]), FakeJob(1, [ FakeStatus('ERROR', 'T0', 'err', False), FakeStatus('GOOD', 'T1', '') ]), FakeJob(2, [FakeStatus('TEST_NA', 'T0', 'no')]), FakeJob(3, [FakeStatus('FAIL', 'T0', 'broken')]), FakeJob(4, [ FakeStatus('ERROR', 'SERVER_JOB', 'server error'), FakeStatus('GOOD', 'T0', '') ]), ] # TODO: Write a better test for the case where we yield # results for aborts vs cannot yield results because of # a premature abort. Currently almost all client aborts # have been converted to failures, and when aborts do happen # they result in server job failures for which we always # want results. # FakeJob(5, [FakeStatus('ERROR', 'T0', 'gah', True)]), # The next job shouldn't be recorded in the results. # FakeJob(6, [FakeStatus('GOOD', 'SERVER_JOB', '')])] for status in jobs[4].statuses: status.entry['job'] = {'name': 'broken_infra_job'} # To simulate a job that isn't ready the first time we check. self.afe.get_jobs(id=jobs[0].id, finished=True).AndReturn([]) # Expect all the rest of the jobs to be good to go the first time. for job in jobs[1:]: self.expect_result_gathering(job) # Then, expect job[0] to be ready. self.expect_result_gathering(jobs[0]) # Expect us to poll twice. self.mox.StubOutWithMock(time, 'sleep') time.sleep(5) time.sleep(5) self.mox.ReplayAll() results = [ result for result in job_status.wait_for_results(self.afe, self.tko, jobs) ] for job in jobs[:6]: # the 'GOOD' SERVER_JOB shouldn't be there. for status in job.statuses: self.assertTrue(True in map(status.equals_record, results))
def testWaitForChildResults(self): """Should gather status and return records for job summaries.""" parent_job_id = 54321 jobs = [ FakeJob( 0, [FakeStatus('GOOD', 'T0', ''), FakeStatus('GOOD', 'T1', '')], parent_job_id=parent_job_id), FakeJob(1, [ FakeStatus('ERROR', 'T0', 'err', False), FakeStatus('GOOD', 'T1', '') ], parent_job_id=parent_job_id), FakeJob(2, [FakeStatus('TEST_NA', 'T0', 'no')], parent_job_id=parent_job_id), FakeJob(3, [FakeStatus('FAIL', 'T0', 'broken')], parent_job_id=parent_job_id), FakeJob(4, [ FakeStatus('ERROR', 'SERVER_JOB', 'server error'), FakeStatus('GOOD', 'T0', '') ], parent_job_id=parent_job_id), ] # TODO: Write a better test for the case where we yield # results for aborts vs cannot yield results because of # a premature abort. Currently almost all client aborts # have been converted to failures and when aborts do happen # they result in server job failures for which we always # want results. #FakeJob(5, [FakeStatus('ERROR', 'T0', 'gah', True)], # parent_job_id=parent_job_id), # The next job shouldn't be recorded in the results. #FakeJob(6, [FakeStatus('GOOD', 'SERVER_JOB', '')], # parent_job_id=12345)] for status in jobs[4].statuses: status.entry['job'] = {'name': 'broken_infra_job'} # Expect one call to get a list of all child jobs. self.afe.get_jobs(parent_job_id=parent_job_id).AndReturn(jobs[:6]) # Have the first two jobs be finished by the first polling, # and the remaining ones (not including #6) for the second polling. self.afe.get_jobs(parent_job_id=parent_job_id, finished=True).AndReturn([jobs[1]]) self.expect_yield_job_entries(jobs[1]) self.afe.get_jobs(parent_job_id=parent_job_id, finished=True).AndReturn(jobs[:2]) self.expect_yield_job_entries(jobs[0]) self.afe.get_jobs(parent_job_id=parent_job_id, finished=True).AndReturn(jobs[:6]) for job in jobs[2:6]: self.expect_yield_job_entries(job) # Then, expect job[0] to be ready. # Expect us to poll thrice self.mox.StubOutWithMock(time, 'sleep') time.sleep(5) time.sleep(5) time.sleep(5) self.mox.ReplayAll() results = [ result for result in job_status.wait_for_child_results( self.afe, self.tko, parent_job_id) ] for job in jobs[:6]: # the 'GOOD' SERVER_JOB shouldn't be there. for status in job.statuses: self.assertTrue(True in map(status.equals_record, results))