def test_return_most_recent_pass(self): """The last time a test passed should be returned.""" # To add a test entry to the database, the test object has to # be instantiated with various other model instances. We give these # instances dummy id values. job = models.Job(job_idx=1) kernel = models.Kernel(kernel_idx=1) machine = models.Machine(machine_idx=1) early_pass = models.Test(job=job, status=GOOD_STATUS, kernel=kernel, machine=machine, test='test', started_time=datetime.datetime(2012, 1, 1)) early_pass.save() late_pass = models.Test(job=job, status=GOOD_STATUS, kernel=kernel, machine=machine, test='test', started_time=datetime.datetime(2012, 1, 2)) late_pass.save() results = utils.get_last_pass_times() self.assertEquals(results, {'test': datetime.datetime(2012, 1, 2)})
def test_only_return_passing_tests(self): """Tests that only tests that have passed at some point are returned.""" job = models.Job(job_idx=1) kernel = models.Kernel(kernel_idx=1) machine = models.Machine(machine_idx=1) passing_test = models.Test(job=job, status=GOOD_STATUS, kernel=kernel, machine=machine, test='passing_test', started_time=datetime.datetime(2012, 1, 1)) passing_test.save() failing_test = models.Test(job=job, status=FAIL_STATUS, kernel=kernel, machine=machine, test='failing_test', started_time=datetime.datetime(2012, 1, 1)) failing_test.save() results = utils.get_last_pass_times() self.assertEquals(results, {'passing_test': datetime.datetime(2012, 1, 1)})
def test_does_not_return_passing_tests(self): """Test that passing test entries are not included.""" job = models.Job(job_idx=1) kernel = models.Kernel(kernel_idx=1) machine = models.Machine(machine_idx=1) passing_test = models.Test(job=job, status=GOOD_STATUS, kernel=kernel, machine=machine, test='passing_test', started_time=datetime.datetime(2012, 1, 1)) passing_test.save() failing_test = models.Test(job=job, status=FAIL_STATUS, kernel=kernel, machine=machine, test='failing_test', started_time=datetime.datetime(2012, 1, 1)) failing_test.save() results = utils.get_last_fail_times() self.assertEquals(results, {'failing_test': datetime.datetime(2012, 1, 1)})
def test_return_all_failing_tests(self): """This function returns all tests that failed at least once.""" job = models.Job(job_idx=1) kernel = models.Kernel(kernel_idx=1) machine = models.Machine(machine_idx=1) test1 = models.Test(job=job, status=FAIL_STATUS, kernel=kernel, machine=machine, test='test1', started_time=datetime.datetime(2012, 1, 1)) test1.save() test2 = models.Test(job=job, status=FAIL_STATUS, kernel=kernel, machine=machine, test='test2', started_time=datetime.datetime(2012, 1, 2)) test2.save() results = utils.get_last_fail_times() self.assertEquals( results, { 'test1': datetime.datetime(2012, 1, 1), 'test2': datetime.datetime(2012, 1, 2) })
def test_returns_no_duplicate_names(self): """Test that each test name appears only once.""" job = models.Job(job_idx=1) kernel = models.Kernel(kernel_idx=1) machine = models.Machine(machine_idx=1) success_status = models.Status(status_idx=GOOD_STATUS_IDX) test = models.Test(job=job, status=success_status, kernel=kernel, machine=machine, test='test', started_time=self.datetime(2012, 1, 1)) test.save() duplicate = models.Test(job=job, status=success_status, kernel=kernel, machine=machine, test='test', started_time=self.datetime(2012, 1, 2)) duplicate.save() datetime.datetime.today().AndReturn(self.datetime(2012, 1, 3)) complete_failures._DAYS_NOT_RUNNING_CUTOFF = 60 self.mox.ReplayAll() results = complete_failures.get_recently_ran_test_names() self.assertEqual(len(results), 1)
def test_return_all_recently_ran_tests(self): """Test that the function does as it says it does.""" job = models.Job(job_idx=1) kernel = models.Kernel(kernel_idx=1) machine = models.Machine(machine_idx=1) success_status = models.Status(status_idx=GOOD_STATUS_IDX) recent = models.Test(job=job, status=success_status, kernel=kernel, machine=machine, test='recent', started_time=self.datetime(2012, 1, 1)) recent.save() old = models.Test(job=job, status=success_status, kernel=kernel, machine=machine, test='old', started_time=self.datetime(2011, 1, 2)) old.save() datetime.datetime.today().AndReturn(self.datetime(2012, 1, 4)) complete_failures._DAYS_NOT_RUNNING_CUTOFF = 60 self.mox.ReplayAll() results = complete_failures.get_recently_ran_test_names() self.assertEqual(set(results), set(['recent']))
def test(self): """Does a basic test of as much of the system as possible.""" afe_models.Test(name='test1', test_type=0, path='test1', experimental=True).save() afe_models.Test(name='test2', test_type=0, path='test2', experimental=True).save() tko_models.Status(status_idx=6, word='GOOD').save() job = tko_models.Job(job_idx=1) kernel = tko_models.Kernel(kernel_idx=1) machine = tko_models.Machine(machine_idx=1) success_status = tko_models.Status(status_idx=GOOD_STATUS_IDX) fail_status = tko_models.Status(status_idx=FAIL_STATUS_IDX) tko_test1 = tko_models.Test(job=job, status=success_status, kernel=kernel, machine=machine, test='test1', started_time=self.datetime(2012, 1, 20)) tko_test1.save() tko_test2 = tko_models.Test(job=job, status=success_status, kernel=kernel, machine=machine, test='test2', started_time=self.datetime(2012, 1, 20)) tko_test2.save() passing_experimental._MAX_DAYS_SINCE_LAST_PASS = 10 passing_experimental._MIN_DAYS_SINCE_FAILURE = 10 MockDatetime.today().AndReturn(self.datetime(2012, 1, 21)) MockDatetime.today().AndReturn(self.datetime(2012, 1, 21)) reporter1 = reporting.Reporter() bug1 = reporting.Bug( title=u'test1 should be promoted to non-experimental.', summary=mox.IgnoreArg(), search_marker=u'PassingExperimental(test1)') reporter1.report(bug1).AndReturn((11, 1)) reporter2 = reporting.Reporter() bug2 = reporting.Bug( title=u'test2 should be promoted to non-experimental.', summary=mox.IgnoreArg(), search_marker=u'PassingExperimental(test2)') reporter2.report(bug2).AndReturn((11, 1)) self.mox.ReplayAll() passing_experimental.main()
def test(self): """Does a basic test of as much of the system as possible.""" job = models.Job(job_idx=1) kernel = models.Kernel(kernel_idx=1) machine = models.Machine(machine_idx=1) success_status = models.Status(status_idx=GOOD_STATUS_IDX) fail_status = models.Status(status_idx=FAIL_STATUS_IDX) old_passing_test = models.Test(job=job, status=success_status, kernel=kernel, machine=machine, test='test1', started_time=self.datetime(2012, 1, 1)) old_passing_test.save() failing_test = models.Test(job=job, status=fail_status, kernel=kernel, machine=machine, test='test2', started_time=self.datetime(2012, 1, 1)) failing_test.save() good_test = models.Test(job=job, status=success_status, kernel=kernel, machine=machine, test='test3', started_time=self.datetime(2012, 1, 20)) good_test.save() complete_failures._DAYS_TO_BE_FAILING_TOO_LONG = 10 MockDatetime.today().AndReturn(self.datetime(2012, 1, 21)) MockDatetime.today().AndReturn(self.datetime(2012, 1, 21)) mail.send( '*****@*****.**', ['*****@*****.**'], [], 'Long Failing Tests', '2/3 tests have been failing for at least %d days.\n' 'They are the following:\n\ntest1\ntest2' % complete_failures._DAYS_TO_BE_FAILING_TOO_LONG) self.mox.ReplayAll() complete_failures.main()
def test_returns_treats_alert_status_as_failure(self): """Alert statuses should count as failures.""" job = models.Job(job_idx=1) kernel = models.Kernel(kernel_idx=1) machine = models.Machine(machine_idx=1) test = models.Test(job=job, status=ALERT_STATUS, kernel=kernel, machine=machine, test='alert', started_time=datetime.datetime(2012, 1, 1)) test.save() results = utils.get_last_fail_times() self.assertEquals(results, {'alert': datetime.datetime(2012, 1, 1)})
def main(args): """ Run passing_experimental.py to check bug filing for it. This sets the fake database up so a bug is guranteed to be filed. However, it requires manually verifying that the bug was filed and deduped. @param args: The arguments passed in from the commandline. """ args = [] if args is None else args parse_options(args) setup_test_environment.set_up() afe_models.Test(name='test_dedupe', test_type=0, path='test_dedupe', experimental=True).save() tko_models.Status(status_idx=6, word='GOOD').save() job = tko_models.Job(job_idx=1) kernel = tko_models.Kernel(kernel_idx=1) machine = tko_models.Machine(machine_idx=1) success_status = tko_models.Status(status_idx=GOOD_STATUS_IDX) tko_dedupe = tko_models.Test(job=job, status=success_status, kernel=kernel, machine=machine, test='test_dedupe', started_time=datetime.datetime.today()) tko_dedupe.save() passing_experimental.main() # We assume that the user is using the dummy tracker when using this script. print('Now check the bug tracker to make sure this was properly deduped.\n' 'https://code.google.com/p/autotest-bug-filing-test/issues/list?' 'q=PassingExperimental')
def test_returns_treats_abort_status_as_failure(self): """ Abort statuses should count as failures. This should be changed once Abort only represents user caused aborts. See issue crbug.com/188217. """ job = models.Job(job_idx=1) kernel = models.Kernel(kernel_idx=1) machine = models.Machine(machine_idx=1) test = models.Test(job=job, status=ABORT_STATUS, kernel=kernel, machine=machine, test='abort', started_time=datetime.datetime(2012, 1, 1)) test.save() results = utils.get_last_fail_times() self.assertEquals(results, {'abort': datetime.datetime(2012, 1, 1)})