def test_dequeue_ignores_nonexisting_jobs(): """Dequeuing silently ignores non-existing jobs.""" q = Queue() uuid = '49f205ab-8ea3-47dd-a1b5-bfa186870fc8' yield from q.push_job_id(uuid) yield from q.push_job_id(uuid) result = yield from q.enqueue(say_hello, 'Nick', foo='bar') yield from q.push_job_id(uuid) # Dequeue simply ignores the missing job and returns None assert (yield from q.count) == 4 assert (yield from q.dequeue()).id == result.id assert not (yield from q.dequeue()) assert not (yield from q.count)
def test_dequeue_deleted_jobs(): """Dequeueing deleted jobs from queues don't blow the stack.""" q = Queue() for _ in range(1, 1000): job = yield from q.enqueue(say_hello) yield from job.delete() yield from q.dequeue()
def test_dequeue_class_method(): """Dequeueing class method jobs from queues.""" q = Queue() yield from q.enqueue(Number.divide, 3, 4) job = yield from q.dequeue() assert job.instance.__dict__ == Number.__dict__ assert job.func.__name__ == 'divide' assert job.args == (3, 4)
def test_dequeue_instance_method(): """Dequeueing instance method jobs from queues.""" q = Queue() n = Number(2) yield from q.enqueue(n.div, 4) job = yield from q.dequeue() # The instance has been pickled and unpickled, so it is now a # separate object. Test for equality using each object's __dict__ # instead. assert job.instance.__dict__ == n.__dict__ assert job.func.__name__ == 'div' assert job.args == (4,)
def test_dequeue(): """Dequeueing jobs from queues.""" # Set up q = Queue() result = yield from q.enqueue(say_hello, 'Rick', foo='bar') # Dequeue a job (not a job ID) off the queue assert (yield from q.count) job = yield from q.dequeue() assert job.id == result.id assert job.func == say_hello assert job.origin == q.name assert job.args[0] == 'Rick' assert job.kwargs['foo'] == 'bar' # ...and assert the queue count when down assert not (yield from q.count)