class TestFlowStore(TestCase): def setUp(self): self.q = Queue() self.w = Worker(self.q) with Flow(self.q, name='test') as f: self.job = f.enqueue(say_hello, 'Bob') self.n_job = f.enqueue(do_nothing) def test_flowstore(self): fs = FlowStore.objects.get(name='test') j1 = Job.objects.get(pk=self.job.id) self.assertEqual(len(fs.jobs), 2) self.assertEqual(fs.status, FlowStore.QUEUED) self.assertEqual(fs.enqueued_at, j1.enqueued_at) self.assertIsNone(fs.ended_at) self.assertIsNone(fs.expired_at) self.w.work(burst=True) fs = FlowStore.objects.get(name='test') self.assertEqual(fs.status, FlowStore.FINISHED) self.assertIsNotNone(fs.ended_at) self.assertIsNotNone(fs.expired_at)
def setUp(self): self.q = Queue() self.w = Worker(self.q) with Flow(self.q, name='test') as f: # enqueue a job to fail self.job = f.enqueue(some_calculation, 2, 3, 0) self.n_job = f.enqueue(do_nothing)
def test_queue_creation_conflict_issue2(self): """Ordinary queue shouldn't ever become a serial queue""" q = Queue.create() self.assertFalse(q.serial) q.enqueue(do_nothing) self.q.enqueue(do_nothing) w = Worker([q, self.q]) w.work(burst=True)
def setUp(self): self.q = Queue() self.w = Worker(self.q, default_result_ttl=1, default_worker_ttl=2.1, expires_after=2) with Flow(self.q, name='test') as f: self.n_job = f.enqueue(do_nothing)
class TestFlowStoreExpiredTTLOnDequeue(TestCase): def setUp(self): self.q = Queue() self.w = Worker(self.q, default_result_ttl=1, default_worker_ttl=2.1, expires_after=2) with Flow(self.q, name='test') as f: self.n_job = f.enqueue(do_nothing) def test_delete_expired_ttl_on_dequeue(self): self.w.work() with self.assertRaises(FlowStore.DoesNotExist): fs = FlowStore.objects.get(name='test')
class TestFlowStoreExpiredTTLOnDequeue(TransactionTestCase): def setUp(self): self.q = Queue() self.w = Worker(self.q, default_result_ttl=1, default_worker_ttl=2.1, expires_after=1) with Flow(self.q, name='test') as f: self.n_job = f.enqueue(do_nothing) def test_delete_expired_ttl_on_dequeue(self): self.w.work() with self.assertRaises(FlowStore.DoesNotExist): fs = FlowStore.objects.get(name='test')
class TestFlowStoreExpiredTTL(TransactionTestCase): def setUp(self): self.q = Queue() self.w = Worker(self.q, default_result_ttl=1) with Flow(self.q, name='test') as f: self.n_job = f.enqueue(do_nothing) def test_delete_expired_ttl(self): self.w.work(burst=True) self.assertIsNotNone(FlowStore.objects.get(name='test')) time.sleep(1) self.w.work(burst=True) with self.assertRaises(FlowStore.DoesNotExist): FlowStore.objects.get(name='test')
class TestFlowStoreExpiredTTL(TestCase): def setUp(self): self.q = Queue() self.w = Worker(self.q, default_result_ttl=1) with Flow(self.q, name='test') as f: self.n_job = f.enqueue(do_nothing) def test_delete_expired_ttl(self): self.w.work(burst=True) self.assertIsNotNone(FlowStore.objects.get(name='test')) time.sleep(1) self.w.work(burst=True) with self.assertRaises(FlowStore.DoesNotExist): fs = FlowStore.objects.get(name='test')
class TestFlowPerform(TransactionTestCase): def setUp(self): self.q = Queue() self.w = Worker(self.q) with Flow(self.q) as f: self.job = f.enqueue(say_hello, 'Bob') self.n_job = f.enqueue(do_nothing) def test_flow_perform(self): self.w.work(burst=True) j1 = Job.objects.get(pk=self.job.id) j2 = Job.objects.get(pk=self.n_job.id) self.assertEqual(Job.FINISHED, j1.status) self.assertEqual(Job.FINISHED, j2.status) self.assertEqual(self.q.count, 0)
class TestFlowPerform(TestCase): def setUp(self): self.q = Queue() self.w = Worker(self.q) with Flow(self.q) as f: self.job = f.enqueue(say_hello, 'Bob') self.n_job = f.enqueue(do_nothing) def test_flow_perform(self): self.w.work(burst=True) j1 = Job.objects.get(pk=self.job.id) j2 = Job.objects.get(pk=self.n_job.id) self.assertEqual(Job.FINISHED, j1.status) self.assertEqual(Job.FINISHED, j2.status) self.assertEqual(self.q.count, 0)
def setUp(self): self.q = Queue() self.w = Worker( self.q, default_result_ttl=1, default_worker_ttl=2.1, expires_after=1 ) with Flow(self.q, name='test') as f: self.n_job = f.enqueue(do_nothing)
class TestFlowStoreFailed(TestCase): def setUp(self): self.q = Queue() self.w = Worker(self.q) with Flow(self.q, name='test') as f: # enqueue a job to fail self.job = f.enqueue(some_calculation, 2, 3, 0) self.n_job = f.enqueue(do_nothing) def test_flowstore_failed(self): fs = FlowStore.objects.get(name='test') self.w.work(burst=True) fs = FlowStore.objects.get(name='test') self.assertEqual(fs.status, FlowStore.FAILED) self.assertIsNone(fs.ended_at) self.assertIsNone(fs.expired_at) n_job = Job.objects.get(pk=self.n_job.id) self.assertIsNone(n_job.queue_id) self.assertEqual(n_job.status, Job.FLOW) job = Job.objects.get(pk=self.job.id) # alter the args so it passes job.args = (2, 3, 2) job.save() fq = FailedQueue.create() fq.requeue(job.id) # do work self.w.work(burst=True) # should now be finished fs = FlowStore.objects.get(name='test') self.assertEqual(fs.status, FlowStore.FINISHED) job = Job.objects.get(pk=self.job.id) n_job = Job.objects.get(pk=self.n_job.id) self.assertEqual(job.status, Job.FINISHED) self.assertEqual(n_job.status, Job.FINISHED)
class TestFlowStoreFailed(TransactionTestCase): def setUp(self): self.q = Queue() self.w = Worker(self.q) with Flow(self.q, name='test') as f: # enqueue a job to fail self.job = f.enqueue(some_calculation, 2, 3, 0) self.n_job = f.enqueue(do_nothing) def test_flowstore_failed(self): fs = FlowStore.objects.get(name='test') self.w.work(burst=True) fs = FlowStore.objects.get(name='test') self.assertEqual(fs.status, FlowStore.FAILED) self.assertIsNone(fs.ended_at) self.assertIsNone(fs.expired_at) n_job = Job.objects.get(pk=self.n_job.id) self.assertIsNone(n_job.queue_id) self.assertEqual(n_job.status, Job.FLOW) job = Job.objects.get(pk=self.job.id) # alter the args so it passes job.args = (2, 3, 2) job.save() fq = FailedQueue.create() fq.requeue(job.id) # do work self.w.work(burst=True) # should now be finished fs = FlowStore.objects.get(name='test') self.assertEqual(fs.status, FlowStore.FINISHED) job = Job.objects.get(pk=self.job.id) n_job = Job.objects.get(pk=self.n_job.id) self.assertEqual(job.status, Job.FINISHED) self.assertEqual(n_job.status, Job.FINISHED)
def setUp(self): self.q = Queue() self.w = Worker(self.q) with Flow(self.q, name='test') as f: self.job = f.enqueue(say_hello, 'Bob') self.n_job = f.enqueue(do_nothing)
def setUp(self): self.q = Queue() self.w = Worker(self.q, default_result_ttl=1) with Flow(self.q, name='test') as f: self.n_job = f.enqueue(do_nothing)