Ejemplo n.º 1
0
 def test_list_tasks(self):
     tasks = [ test_task.post() ]
     self.assertEqual(
         TaskObject.list(),
         '\n'.join(map(repr, tasks)))
     tasks.append(test_task.post())
     self.assertEqual(
         len(TaskObject.list()),
         len('\n'.join(map(repr, tasks))))
Ejemplo n.º 2
0
 def test_clear_complete_keep(self):
     # Create complete, 'keep' task
     doc = TaskDoc.make(dict(
             task=dict(name='foo', args=[], kwargs={}),
             result_type='keep',
             state='complete'))
     doc.m.save()
     # timeout tasks
     TaskObject.clear_complete()
     # Make sure the doc is gone
     self.assertEqual(TaskDoc.m.find().count(), 1)
Ejemplo n.º 3
0
 def test_run_ready(self):
     # Create two tasks
     test_task.post()
     test_task.post()
     # Run all the ready tasks
     TaskObject.run_ready()
     # Verify that all the tasks are complete
     self.assertEqual(
         0, TaskDoc.m.find(dict(state='ready')).count())
     self.assertEqual(
         2, TaskDoc.m.find(dict(state='complete')).count())
Ejemplo n.º 4
0
 def test_timeout_tasks(self):
     # Create busy task
     doc = TaskDoc.make(dict(
             task=dict(name='foo',args=[],kwargs={}),
             time=dict(start=datetime.utcnow()),
             state='busy'))
     doc.m.save()
     # timeout tasks
     TaskObject.timeout_tasks(
         datetime.utcnow() + timedelta(seconds=10))
     doc = TaskDoc.m.get()
     # Make sure the doc is ready and unlocked
     self.assertEqual(doc.state, 'ready')
     self.assertEqual(doc.process, None)
Ejemplo n.º 5
0
 def test_task_with_exceptions(self):
     bad_task.post()
     t = TaskObject.get()
     self.assertRaises(ValueError, t)
     self.assertEqual(t.state, 'error')
     self.assertEqual(
         'ValueError', t.result.split('\n')[-2])
Ejemplo n.º 6
0
 def test_get_empty_queue(self):
     obj = TaskObject.get()
     self.assertEqual(obj, None)
Ejemplo n.º 7
0
 def test_get_task(self):
     test_task.post(1, 2, a=5)
     obj = TaskObject.get()
     self.assertEqual(obj.process, 'worker')
     self.assertEqual(obj.state, 'busy')
Ejemplo n.º 8
0
 def test_run_task(self):
     test_task.post()
     t = TaskObject.get()
     self.assertEqual(t(), 42)
     self.assertEqual(t.state, 'complete')
     self.assertEqual(t.result, 42)