def test_enqueue_job_at_front(redis): """Enqueue job at front must add its id to the front of the queue.""" yield from redis.lpush(queue_key(stubs.queue), 'xxx') yield from enqueue_job(redis=redis, at_front=True, **stubs.job) queue_content = [stubs.job_id.encode(), b'xxx'] assert (yield from redis.lrange(queue_key(stubs.queue), 0, -1)) == queue_content
def test_compact_queue(redis): """Compact queue. Clean non existing jobs.""" yield from redis.rpush(queue_key(stubs.queue), 'foo') yield from enqueue_job(redis=redis, **stubs.job) yield from redis.rpush(queue_key(stubs.queue), 'bar') yield from compact_queue(redis, stubs.queue) assert (yield from jobs(redis, stubs.queue)) == [stubs.job_id.encode()]
def test_enqueue_job_at_front(redis): """Enqueue job at front must add its id to the front of the queue.""" yield from redis.lpush(queue_key(stubs.queue), 'xxx') yield from enqueue_job(redis=redis, at_front=True, **stubs.job) queue_content = [stubs.job_id.encode(), b'xxx'] assert (yield from redis.lrange(queue_key(stubs.queue), 0, -1)) == queue_content
def test_empty_queue(redis): """Emptying queue.""" yield from redis.rpush(queue_key(stubs.queue), 'foo') yield from redis.rpush(queue_key(stubs.queue), 'bar') assert (yield from queue_length(redis, stubs.queue)) yield from empty_queue(redis, stubs.queue) assert not (yield from queue_length(redis, stubs.queue))
def test_empty_queue(redis): """Emptying queue.""" yield from redis.rpush(queue_key(stubs.queue), 'foo') yield from redis.rpush(queue_key(stubs.queue), 'bar') assert (yield from queue_length(redis, stubs.queue)) yield from empty_queue(redis, stubs.queue) assert not (yield from queue_length(redis, stubs.queue))
def test_compact_queue(redis): """Compact queue. Clean non existing jobs.""" yield from redis.rpush(queue_key(stubs.queue), 'foo') yield from enqueue_job(redis=redis, **stubs.job) yield from redis.rpush(queue_key(stubs.queue), 'bar') yield from compact_queue(redis, stubs.queue) assert (yield from jobs(redis, stubs.queue)) == [stubs.job_id.encode()]
def test_enqueue_job_add_job_key_to_the_queue(redis): """Enqueue job must add its id to the queue.""" yield from enqueue_job(redis=redis, **stubs.job) queue_content = [stubs.job_id.encode()] assert (yield from redis.lrange(queue_key(stubs.queue), 0, -1)) == queue_content
def test_dequeue_job_no_such_job(redis): """Silently skip job ids from queue if there is no such job hash.""" yield from redis.rpush(queue_key(stubs.queue), 'foo') # Job id without hash. yield from enqueue_job(redis=redis, **stubs.job) stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue) assert stored_id == stubs.job_id.encode()
def test_enqueue_job_defer_dependent(redis): """Defer dependent job. It shouldn't present in the queue.""" yield from enqueue_job(redis=redis, **stubs.job) yield from enqueue_job(redis=redis, **stubs.child_job) assert (yield from redis.lrange(queue_key(stubs.queue), 0, -1)) == [stubs.job_id.encode()]
def test_dequeue_job_no_such_job(redis): """Silently skip job ids from queue if there is no such job hash.""" yield from redis.rpush(queue_key(stubs.queue), 'foo') # Job id without hash. yield from enqueue_job(redis=redis, **stubs.job) stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue) assert stored_id == stubs.job_id.encode()
def test_finish_job_enqueue_dependents(redis): """Finish job will enqueue its dependents.""" yield from enqueue_job(redis=redis, **stubs.job) yield from enqueue_job(redis=redis, **stubs.child_job) stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue) stored_id = stored_id.decode() queue = stored_spec[b'origin'].decode() timeout = stored_spec[b'timeout'] yield from start_job(redis, queue, stored_id, timeout) yield from finish_job(redis, queue, stored_id) assert (yield from redis.lrange(queue_key(stubs.queue), 0, -1)) == [stubs.child_job_id.encode()]
def test_enqueue_job_finished_dependency(redis): """Enqueue job immediately if its dependency already finished.""" yield from enqueue_job(redis=redis, **stubs.job) stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue) stored_id = stored_id.decode() queue = stored_spec[b'origin'].decode() timeout = stored_spec[b'timeout'] yield from start_job(redis, queue, stored_id, timeout) yield from finish_job(redis, queue, stored_id) yield from enqueue_job(redis=redis, **stubs.child_job) assert (yield from redis.lrange(queue_key(stubs.queue), 0, -1)) == [stubs.child_job_id.encode()]
def test_finish_job_enqueue_dependents(redis): """Finish job will enqueue its dependents.""" yield from enqueue_job(redis=redis, **stubs.job) yield from enqueue_job(redis=redis, **stubs.child_job) stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue) stored_id = stored_id.decode() queue = stored_spec[b'origin'].decode() timeout = stored_spec[b'timeout'] yield from start_job(redis, queue, stored_id, timeout) yield from finish_job(redis, queue, stored_id) assert (yield from redis.lrange(queue_key(stubs.queue), 0, -1)) == [stubs.child_job_id.encode()]
def test_enqueue_job_finished_dependency(redis): """Enqueue job immediately if its dependency already finished.""" yield from enqueue_job(redis=redis, **stubs.job) stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue) stored_id = stored_id.decode() queue = stored_spec[b'origin'].decode() timeout = stored_spec[b'timeout'] yield from start_job(redis, queue, stored_id, timeout) yield from finish_job(redis, queue, stored_id) yield from enqueue_job(redis=redis, **stubs.child_job) assert (yield from redis.lrange(queue_key(stubs.queue), 0, -1)) == [stubs.child_job_id.encode()]
def test_queue_length(redis): """RQ queue size.""" yield from redis.rpush(queue_key(stubs.queue), 'foo') yield from redis.rpush(queue_key(stubs.queue), 'bar') assert (yield from queue_length(redis, stubs.queue)) == 2
def test_jobs_args(redis): """Test jobs behavior with limit and offset arguments.""" yield from redis.rpush(queue_key(stubs.queue), 'foo') yield from redis.rpush(queue_key(stubs.queue), 'bar') assert set((yield from jobs(redis, stubs.queue, 0, 0))) == {b'foo'}
def test_enqueue_job_add_job_key_to_the_queue(redis): """Enqueue job must add its id to the queue.""" yield from enqueue_job(redis=redis, **stubs.job) queue_content = [stubs.job_id.encode()] assert (yield from redis.lrange(queue_key(stubs.queue), 0, -1)) == queue_content
def test_jobs(redis): """All queue jobs.""" yield from redis.rpush(queue_key(stubs.queue), 'foo') yield from redis.rpush(queue_key(stubs.queue), 'bar') assert set((yield from jobs(redis, stubs.queue))) == {b'foo', b'bar'}
def test_enqueue_job_defer_dependent(redis): """Defer dependent job. It shouldn't present in the queue.""" yield from enqueue_job(redis=redis, **stubs.job) yield from enqueue_job(redis=redis, **stubs.child_job) assert (yield from redis.lrange(queue_key(stubs.queue), 0, -1)) == [stubs.job_id.encode()]
def test_jobs(redis): """All queue jobs.""" yield from redis.rpush(queue_key(stubs.queue), 'foo') yield from redis.rpush(queue_key(stubs.queue), 'bar') assert set((yield from jobs(redis, stubs.queue))) == {b'foo', b'bar'}
def test_jobs_args(redis): """Test jobs behavior with limit and offset arguments.""" yield from redis.rpush(queue_key(stubs.queue), 'foo') yield from redis.rpush(queue_key(stubs.queue), 'bar') assert set((yield from jobs(redis, stubs.queue, 0, 0))) == {b'foo'}
def test_queue_length(redis): """RQ queue size.""" yield from redis.rpush(queue_key(stubs.queue), 'foo') yield from redis.rpush(queue_key(stubs.queue), 'bar') assert (yield from queue_length(redis, stubs.queue)) == 2