示例#1
0
 def test_tasks_run_cancel_scheduled(self):
     task = self._task_for_object(TestModel.run_something_long, 'key1')
     with LogCheck(self):
         Task.objects._do_schedule()
     djangotasks.run_task(task)
     djangotasks.cancel_task(task)
     with LogCheck(
             self, "INFO: Cancelling task " + str(task.pk) +
             "...\nINFO: Task " + str(task.pk) +
             " finished with status \"cancelled\"\nINFO: ...Task " +
             str(task.pk) + " cancelled.\n"):
         Task.objects._do_schedule()
     new_task = Task.objects.get(pk=task.pk)
     self.assertEquals("cancelled", new_task.status)
     self.assertEquals("", new_task.log)
示例#2
0
 def test_tasks_run_cancel_scheduled(self):
     task = self._task_for_object(TestModel.run_something_long, "key1")
     with LogCheck(self):
         Task.objects._do_schedule()
     djangotasks.run_task(task)
     djangotasks.cancel_task(task)
     with LogCheck(
         self,
         "INFO: Cancelling task "
         + str(task.pk)
         + "...\nINFO: Task "
         + str(task.pk)
         + ' finished with status "cancelled"\nINFO: ...Task '
         + str(task.pk)
         + " cancelled.\n",
     ):
         Task.objects._do_schedule()
     new_task = Task.objects.get(pk=task.pk)
     self.assertEquals("cancelled", new_task.status)
     self.assertEquals("", new_task.log)
示例#3
0
    def test_tasks_run_cancel_running(self):
        task = self._task_for_object(TestModel.run_something_long, "key1")
        djangotasks.run_task(task)
        with LogCheck(self, _start_message(task)):
            Task.objects._do_schedule()
        self._wait_until("key1", "run_something_long_1")
        djangotasks.cancel_task(task)
        output_check = LogCheck(self, fail_if_different=False)
        with output_check:
            Task.objects._do_schedule()
            time.sleep(0.3)
        self.assertTrue(("Cancelling task " + str(task.pk) + "...") in output_check.log.getvalue())
        self.assertTrue("cancelled.\n" in output_check.log.getvalue())
        # self.assertTrue('INFO: failed to mark tasked as finished, from status "running" to "unsuccessful" for task 3. May have been finished in a different thread already.\n'
        #                in output_check.log.getvalue())

        new_task = Task.objects.get(pk=task.pk)
        self.assertEquals("cancelled", new_task.status)
        self.assertTrue(u"running run_something_long_1" in new_task.log)
        self.assertFalse(u"running run_something_long_2" in new_task.log)
        self.assertFalse("finished" in new_task.log)
示例#4
0
    def test_tasks_run_cancel_running(self):
        task = self._task_for_object(TestModel.run_something_long, 'key1')
        djangotasks.run_task(task)
        with LogCheck(self, _start_message(task)):
            Task.objects._do_schedule()
        self._wait_until('key1', "run_something_long_1")
        djangotasks.cancel_task(task)
        output_check = LogCheck(self, fail_if_different=False)
        with output_check:
            Task.objects._do_schedule()
            time.sleep(0.3)
        self.assertTrue(("Cancelling task " + str(task.pk) +
                         "...") in output_check.log.getvalue())
        self.assertTrue("cancelled.\n" in output_check.log.getvalue())
        #self.assertTrue('INFO: failed to mark tasked as finished, from status "running" to "unsuccessful" for task 3. May have been finished in a different thread already.\n'
        #                in output_check.log.getvalue())

        new_task = Task.objects.get(pk=task.pk)
        self.assertEquals("cancelled", new_task.status)
        self.assertTrue(u'running run_something_long_1' in new_task.log)
        self.assertFalse(u'running run_something_long_2' in new_task.log)
        self.assertFalse('finished' in new_task.log)