def test_tasks_run_two_dependent_tasks_successful(self): key = 'key2' dependent_task = self._create_object_and_test_task( 'run_something_long', key) with_dependent_task = self._create_object_and_test_task( 'run_something_with_dependent', key) task = self._create_object_and_test_task( 'run_something_with_two_dependent', key) self.assertEquals("defined", dependent_task.status) task.run() self._assert_status("scheduled", task) self._assert_status("scheduled", dependent_task) self._check_running(key, dependent_task, None, 'run_something_long_2') self._check_running(key, with_dependent_task, dependent_task, 'run_something_with_dependent') self._check_running(key, task, with_dependent_task, 'run_something_with_two_dependent') task = Task.objects.get(pk=task.pk) complete_log, _ = DATETIME_REGEX.subn('', task.complete_log()) self.assertEquals( u'djangotasks.testmodel.run_something_long(pk = %s/key2) started on \n' % self.tempdir + u'running run_something_long_1\n' + u'running run_something_long_2\n' + u'\n' + u'djangotasks.testmodel.run_something_long(pk = %s/key2) finished successfully on \n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent(pk = %s/key2) started on \n' % self.tempdir + u'running run_something_with_dependent\n' + u'\n' + u'djangotasks.testmodel.run_something_with_dependent(pk = %s/key2) finished successfully on \n' % self.tempdir + u'djangotasks.testmodel.run_something_with_two_dependent(pk = %s/key2) started on \n' % self.tempdir + u'running run_something_with_two_dependent\n' + u'\n' + u'djangotasks.testmodel.run_something_with_two_dependent(pk = %s/key2) finished successfully on ' % self.tempdir, complete_log) complete_log_direct, _ = DATETIME_REGEX.subn('', task.complete_log(True)) self.assertEquals( u'djangotasks.testmodel.run_something_long(pk = %s/key2) started on \n' % self.tempdir + u'running run_something_long_1\n' + u'running run_something_long_2\n' + u'\n' + u'djangotasks.testmodel.run_something_long(pk = %s/key2) finished successfully on \n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent(pk = %s/key2) started on \n' % self.tempdir + u'running run_something_with_dependent\n' + u'\n' + u'djangotasks.testmodel.run_something_with_dependent(pk = %s/key2) finished successfully on \n' % self.tempdir + u'djangotasks.testmodel.run_something_with_two_dependent(pk = %s/key2) started on \n' % self.tempdir + u'running run_something_with_two_dependent\n' + u'\n' + u'djangotasks.testmodel.run_something_with_two_dependent(pk = %s/key2) finished successfully on ' % self.tempdir, complete_log_direct)
def test_tasks_run_dependent_with_two_dependent_tasks_successful(self): key = 'key3' dependent_task = self._create_object_and_test_task('run_something_long', key) with_dependent_task = self._create_object_and_test_task('run_something_with_dependent', key) with_two_dependent_task = self._create_object_and_test_task('run_something_with_two_dependent', key) task = self._create_object_and_test_task('run_something_with_dependent_with_two_dependent', key) self.assertEquals("defined", dependent_task.status) task.run() self._assert_status("scheduled", task) self._assert_status("scheduled", with_dependent_task) self._assert_status("scheduled", with_two_dependent_task) self._assert_status("scheduled", dependent_task) self._check_running(key, dependent_task, None, 'run_something_long_2') self._check_running(key, with_dependent_task, dependent_task, "run_something_with_dependent") self._check_running(key, with_two_dependent_task, with_dependent_task, "run_something_with_two_dependent") self._check_running(key, task, with_two_dependent_task, "run_something_with_dependent_with_two_dependent") task = Task.objects.get(pk=task.pk) complete_log, _ = DATETIME_REGEX.subn('', task.complete_log()) self.assertEquals(u'djangotasks.testmodel.run_something_long(pk = %s/key3) started on \n' % self.tempdir + u'running run_something_long_1\n' + u'running run_something_long_2\n' + u'\n' + u'djangotasks.testmodel.run_something_long(pk = %s/key3) finished successfully on \n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent(pk = %s/key3) started on \n' % self.tempdir + u'running run_something_with_dependent\n' + u'\n' + u'djangotasks.testmodel.run_something_with_dependent(pk = %s/key3) finished successfully on \n' % self.tempdir + u'djangotasks.testmodel.run_something_with_two_dependent(pk = %s/key3) started on \n' % self.tempdir + u'running run_something_with_two_dependent\n' + u'\n' + u'djangotasks.testmodel.run_something_with_two_dependent(pk = %s/key3) finished successfully on \n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent_with_two_dependent(pk = %s/key3) started on \n' % self.tempdir + u'running run_something_with_dependent_with_two_dependent\n' + u'\n' + u'djangotasks.testmodel.run_something_with_dependent_with_two_dependent(pk = %s/key3) finished successfully on ' % self.tempdir, complete_log) complete_log_direct, _ = DATETIME_REGEX.subn('', task.complete_log(True)) self.assertEquals(u'djangotasks.testmodel.run_something_with_two_dependent(pk = %s/key3) started on \n' % self.tempdir + u'running run_something_with_two_dependent\n' + u'\n' + u'djangotasks.testmodel.run_something_with_two_dependent(pk = %s/key3) finished successfully on \n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent_with_two_dependent(pk = %s/key3) started on \n' % self.tempdir + u'running run_something_with_dependent_with_two_dependent\n' + u'\n' + u'djangotasks.testmodel.run_something_with_dependent_with_two_dependent(pk = %s/key3) finished successfully on ' % self.tempdir, complete_log_direct)
def test_run_function_task_with_dependent(self): task = _test_function_with_dependent() task = task.run() self.assertEquals("scheduled", task.status) if True: # with LogCheck(self): Task.objects._do_schedule() time.sleep(0.5) with LogCheck(self): Task.objects._do_schedule() time.sleep(0.5) with LogCheck(self): Task.objects._do_schedule() i = 0 while i < 100: # 20 seconds should be enough i += 1 time.sleep(0.2) task = Task.objects.get(pk=task.pk) if task.status == "successful": break self.assertEquals("successful", task.status) self.assertEquals("running _test_function_with_dependent\n", task.log) complete_log, _ = DATETIME_REGEX.subn('', task.complete_log(True)) self.assertEquals( u'djangotasks.functiontask.run_function_task(pk = djangotasks.tests._test_function) started on \n' + u'running _test_function\n\n' + u'djangotasks.functiontask.run_function_task(pk = djangotasks.tests._test_function) finished successfully on \n' + u'djangotasks.functiontask.run_function_task(pk = djangotasks.tests._test_function_with_dependent) started on \n' + u'running _test_function_with_dependent\n\n' + u'djangotasks.functiontask.run_function_task(pk = djangotasks.tests._test_function_with_dependent) finished successfully on ', complete_log)
def test_run_function_task_with_dependent(self): task = _test_function_with_dependent() task = task.run() self.assertEquals("scheduled", task.status) if True: # with LogCheck(self): Task.objects._do_schedule() time.sleep(0.5) with LogCheck(self): Task.objects._do_schedule() time.sleep(0.5) with LogCheck(self): Task.objects._do_schedule() i = 0 while i < 100: # 20 seconds should be enough i += 1 time.sleep(0.2) task = Task.objects.get(pk=task.pk) if task.status == "successful": break self.assertEquals("successful", task.status) self.assertEquals("running _test_function_with_dependent\n", task.log) complete_log, _ = DATETIME_REGEX.subn('', task.complete_log(True)) self.assertEquals(u'djangotasks.functiontask.run_function_task(pk = djangotasks.tests._test_function) started on \n' + u'running _test_function\n\n' + u'djangotasks.functiontask.run_function_task(pk = djangotasks.tests._test_function) finished successfully on \n' + u'djangotasks.functiontask.run_function_task(pk = djangotasks.tests._test_function_with_dependent) started on \n' + u'running _test_function_with_dependent\n\n' + u'djangotasks.functiontask.run_function_task(pk = djangotasks.tests._test_function_with_dependent) finished successfully on ', complete_log)
def test_tasks_run_dependent_task_failing(self): dependent_task = self._create_object_and_test_task('run_something_failing', 'key1') task = self._create_object_and_test_task('run_something_with_dependent_failing', 'key1') self.assertEquals("defined", dependent_task.status) task.run() self._assert_status("scheduled", task) self._assert_status("scheduled", dependent_task) with LogCheck(self, _start_message(dependent_task)): Task.objects._do_schedule() time.sleep(0.5) self._assert_status("scheduled", task) self._assert_status("running", dependent_task) self._wait_until('key1', 'run_something_failing') time.sleep(0.5) self._assert_status("scheduled", task) self._assert_status("unsuccessful", dependent_task) with LogCheck(self): Task.objects._do_schedule() time.sleep(0.5) self._assert_status("unsuccessful", task) task = Task.objects.get(pk=task.pk) complete_log, _ = DATETIME_REGEX.subn('', task.complete_log()) self.assertTrue(complete_log.startswith('djangotasks.testmodel.run_something_failing(pk = %s/key1) started on \n' % self.tempdir + 'running run_something_failing\n' + 'Traceback (most recent call last):\n')) self.assertTrue(complete_log.endswith(u', in run_something_failing\n' + u' raise Exception("Failed !")\n' + u'Exception: Failed !\n\n' + u'djangotasks.testmodel.run_something_failing(pk = %s/key1) failed on \n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent_failing(pk = %s/key1) started\n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent_failing(pk = %s/key1) failed' % self.tempdir)) complete_log_direct, _ = DATETIME_REGEX.subn('', task.complete_log(True)) self.assertTrue(complete_log_direct.startswith('djangotasks.testmodel.run_something_failing(pk = %s/key1) started on \n' % self.tempdir + u'running run_something_failing\n' + u'Traceback (most recent call last):\n')) self.assertTrue(complete_log_direct.endswith(u', in run_something_failing\n' + u' raise Exception("Failed !")\n' + u'Exception: Failed !\n\n' + u'djangotasks.testmodel.run_something_failing(pk = %s/key1) failed on \n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent_failing(pk = %s/key1) started\n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent_failing(pk = %s/key1) failed' % self.tempdir)) self.assertEquals("unsuccessful", task.status)
def test_tasks_run_dependent_task_failing(self): dependent_task = self._create_object_and_test_task( 'run_something_failing', 'key1') task = self._create_object_and_test_task( 'run_something_with_dependent_failing', 'key1') self.assertEquals("defined", dependent_task.status) task.run() self._assert_status("scheduled", task) self._assert_status("scheduled", dependent_task) with LogCheck(self, _start_message(dependent_task)): Task.objects._do_schedule() time.sleep(0.5) self._assert_status("scheduled", task) self._assert_status("running", dependent_task) self._wait_until('key1', 'run_something_failing') time.sleep(0.5) self._assert_status("scheduled", task) self._assert_status("unsuccessful", dependent_task) with LogCheck(self): Task.objects._do_schedule() time.sleep(0.5) self._assert_status("unsuccessful", task) task = Task.objects.get(pk=task.pk) complete_log, _ = DATETIME_REGEX.subn('', task.complete_log()) self.assertTrue( complete_log.startswith( 'djangotasks.testmodel.run_something_failing(pk = %s/key1) started on \n' % self.tempdir + 'running run_something_failing\n' + 'Traceback (most recent call last):\n')) self.assertTrue( complete_log.endswith( u', in run_something_failing\n' + u' raise Exception("Failed !")\n' + u'Exception: Failed !\n\n' + u'djangotasks.testmodel.run_something_failing(pk = %s/key1) failed on \n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent_failing(pk = %s/key1) started\n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent_failing(pk = %s/key1) failed' % self.tempdir)) complete_log_direct, _ = DATETIME_REGEX.subn('', task.complete_log(True)) self.assertTrue( complete_log_direct.startswith( 'djangotasks.testmodel.run_something_failing(pk = %s/key1) started on \n' % self.tempdir + u'running run_something_failing\n' + u'Traceback (most recent call last):\n')) self.assertTrue( complete_log_direct.endswith( u', in run_something_failing\n' + u' raise Exception("Failed !")\n' + u'Exception: Failed !\n\n' + u'djangotasks.testmodel.run_something_failing(pk = %s/key1) failed on \n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent_failing(pk = %s/key1) started\n' % self.tempdir + u'djangotasks.testmodel.run_something_with_dependent_failing(pk = %s/key1) failed' % self.tempdir)) self.assertEquals("unsuccessful", task.status)