示例#1
0
def test_enqueue_job_store_job_hash(redis):
    """Storing jobs."""

    yield from enqueue_job(redis=redis, **stubs.job)
    assert (yield from redis.type(job_key(stubs.job_id))) == b'hash'
    assert (yield from redis.hget(job_key(stubs.job_id),
                                  'data')) == stubs.job_data
示例#2
0
def test_start_job_persist_job(redis):
    """Start job set persistence to the job hash during job execution."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from redis.expire(job_key(stubs.job_id), 3)
    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)
    assert (yield from redis.ttl(job_key(stubs.job_id))) == -1
示例#3
0
def test_start_job_persist_job(redis):
    """Start job set persistence to the job hash during job execution."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from redis.expire(job_key(stubs.job_id), 3)
    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)
    assert (yield from redis.ttl(job_key(stubs.job_id))) == -1
示例#4
0
def test_enqueue_job_defer_without_date(redis):
    """Enqueue job with dependency doesn't set enqueued_at date."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    assert not (yield from redis.hexists(job_key(stubs.child_job_id),
                                         'enqueued_at'))
示例#5
0
def test_requeue_job_clean_exc_info(redis):
    """Requeue existing job cleanup exception information."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    yield from fail_job(redis, stubs.queue, stubs.job_id, stubs.job_exc_info)
    yield from requeue_job(redis, stored_id.decode())
    assert not (yield from redis.hget(job_key(stubs.job_id), 'exc_info'))
示例#6
0
def test_requeue_job_clean_exc_info(redis):
    """Requeue existing job cleanup exception information."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    yield from fail_job(redis, stubs.queue, stubs.job_id, stubs.job_exc_info)
    yield from requeue_job(redis, stored_id.decode())
    assert not (yield from redis.hget(job_key(stubs.job_id), 'exc_info'))
示例#7
0
def test_job(redis):
    """Get job hash by its id."""

    expected = {b'result_ttl': 5000}
    expected.update({k.encode(): v.encode() if isinstance(v, str) else v
                     for k, v in stubs.job.items()})
    pairs = itertools.chain.from_iterable(expected.items())
    yield from redis.hmset(job_key(stubs.job_id), *pairs)
    assert (yield from job(redis, stubs.job_id)) == expected
示例#8
0
def test_finish_job_sets_results_ttl(redis):
    """Finish job sets results TTL."""

    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)
    assert (yield from redis.ttl(job_key(stubs.job_id))) == 500
示例#9
0
def test_job(redis):
    """Get job hash by its id."""

    expected = {b'result_ttl': 5000}
    expected.update({
        k.encode(): v.encode() if isinstance(v, str) else v
        for k, v in stubs.job.items()
    })
    pairs = itertools.chain.from_iterable(expected.items())
    yield from redis.hmset(job_key(stubs.job_id), *pairs)
    assert (yield from job(redis, stubs.job_id)) == expected
示例#10
0
def test_finish_job_sets_results_ttl(redis):
    """Finish job sets results TTL."""

    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)
    assert (yield from redis.ttl(job_key(stubs.job_id))) == 500
示例#11
0
def test_start_job_sets_started_time(redis):
    """Start job sets it started at time."""

    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)
    started_at = yield from redis.hget(job_key(stubs.job_id), 'started_at')
    assert started_at == utcformat(utcnow()).encode()
示例#12
0
def test_start_job_sets_started_time(redis):
    """Start job sets it started at time."""

    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)
    started_at = yield from redis.hget(job_key(stubs.job_id), 'started_at')
    assert started_at == utcformat(utcnow()).encode()
示例#13
0
def test_finish_job_sets_ended_at(redis):
    """Finish job sets ended at field."""

    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)
    ended_at = yield from redis.hget(job_key(stubs.job_id), 'ended_at')
    assert ended_at == utcformat(utcnow()).encode()
示例#14
0
def test_finish_job_sets_ended_at(redis):
    """Finish job sets ended at field."""

    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)
    ended_at = yield from redis.hget(job_key(stubs.job_id), 'ended_at')
    assert ended_at == utcformat(utcnow()).encode()
示例#15
0
def test_finish_job_remove_results_zero_ttl(redis):
    """Finish job removes jobs with zero TTL."""

    yield from enqueue_job(redis=redis, result_ttl=0, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    queue = stored_spec[b'origin'].decode()
    stored_id = stored_id.decode()
    timeout = stored_spec[b'timeout']
    result_ttl = stored_spec[b'result_ttl']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id, result_ttl=result_ttl)
    assert not (yield from redis.exists(job_key(stubs.job_id)))
示例#16
0
def test_finish_job_non_expired_job(redis):
    """Finish job persist non expired job."""

    yield from enqueue_job(redis=redis, result_ttl=None, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    queue = stored_spec[b'origin'].decode()
    stored_id = stored_id.decode()
    timeout = stored_spec[b'timeout']
    result_ttl = stored_spec[b'result_ttl']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id, result_ttl=result_ttl)
    assert (yield from redis.ttl(job_key(stubs.job_id))) == -1
示例#17
0
def test_finish_job_enqueue_dependents_status(redis):
    """Finish job will set dependents status to QUEUED."""

    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.hget(job_key(stubs.child_job_id), 'status')) == JobStatus.QUEUED.encode()
示例#18
0
def test_finish_job_non_expired_job(redis):
    """Finish job persist non expired job."""

    yield from enqueue_job(redis=redis, result_ttl=None, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    queue = stored_spec[b'origin'].decode()
    stored_id = stored_id.decode()
    timeout = stored_spec[b'timeout']
    result_ttl = stored_spec[b'result_ttl']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id, result_ttl=result_ttl)
    assert (yield from redis.ttl(job_key(stubs.job_id))) == -1
示例#19
0
def test_finish_job_remove_results_zero_ttl(redis):
    """Finish job removes jobs with zero TTL."""

    yield from enqueue_job(redis=redis, result_ttl=0, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    queue = stored_spec[b'origin'].decode()
    stored_id = stored_id.decode()
    timeout = stored_spec[b'timeout']
    result_ttl = stored_spec[b'result_ttl']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id, result_ttl=result_ttl)
    assert not (yield from redis.exists(job_key(stubs.job_id)))
示例#20
0
def test_finish_job_dependents_enqueue_date(redis):
    """Finish job will enqueue its dependents with proper date field."""

    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)
    enqueued_at = yield from redis.hget(job_key(stubs.job_id), 'enqueued_at')
    assert enqueued_at == utcformat(utcnow()).encode()
示例#21
0
def test_finish_job_dependents_enqueue_date(redis):
    """Finish job will enqueue its dependents with proper date field."""

    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)
    enqueued_at = yield from redis.hget(job_key(stubs.job_id), 'enqueued_at')
    assert enqueued_at == utcformat(utcnow()).encode()
示例#22
0
def test_finish_job_enqueue_dependents_status(redis):
    """Finish job will set dependents status to QUEUED."""

    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.hget(job_key(stubs.child_job_id),
                                  'status')) == JobStatus.QUEUED.encode()
示例#23
0
def test_enqueue_job_defer_without_date(redis):
    """Enqueue job with dependency doesn't set enqueued_at date."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    assert not (yield from redis.hexists(job_key(stubs.child_job_id), 'enqueued_at'))
示例#24
0
def test_fail_job_sets_exc_info(redis):
    """Failed job should have exception information."""

    yield from fail_job(redis, stubs.queue, stubs.job_id, stubs.job_exc_info)
    exc_info = yield from redis.hget(job_key(stubs.job_id), 'exc_info')
    assert exc_info == stubs.job_exc_info.encode()
示例#25
0
def test_fail_job_sets_ended_at(redis):
    """Failed job should have ended at time."""

    yield from fail_job(redis, stubs.queue, stubs.job_id, stubs.job_exc_info)
    ended_at = yield from redis.hget(job_key(stubs.job_id), 'ended_at')
    assert ended_at == utcformat(utcnow()).encode()
示例#26
0
def test_job_status(redis):
    """Get job status."""

    yield from redis.hset(job_key(stubs.job_id), 'status', JobStatus.QUEUED)
    assert (yield from job_status(redis,
                                  stubs.job_id)) == JobStatus.QUEUED.encode()
示例#27
0
def test_fail_job_sets_ended_at(redis):
    """Failed job should have ended at time."""

    yield from fail_job(redis, stubs.queue, stubs.job_id, stubs.job_exc_info)
    ended_at = yield from redis.hget(job_key(stubs.job_id), 'ended_at')
    assert ended_at == utcformat(utcnow()).encode()
示例#28
0
def test_enqueue_job_store_job_hash(redis):
    """Storing jobs."""

    yield from enqueue_job(redis=redis, **stubs.job)
    assert (yield from redis.type(job_key(stubs.job_id))) == b'hash'
    assert (yield from redis.hget(job_key(stubs.job_id), 'data')) == stubs.job_data
示例#29
0
def test_enqueue_job_set_job_origin(redis):
    """Enqueue job must set jobs origin queue."""

    yield from enqueue_job(redis=redis, **stubs.job)
    assert (yield from redis.hget(job_key(stubs.job_id), 'origin')) == stubs.queue.encode()
示例#30
0
def test_enqueue_job_set_job_origin(redis):
    """Enqueue job must set jobs origin queue."""

    yield from enqueue_job(redis=redis, **stubs.job)
    assert (yield from redis.hget(job_key(stubs.job_id),
                                  'origin')) == stubs.queue.encode()
示例#31
0
def test_enqueue_job_set_job_enqueued_at(redis):
    """Enqueue job must set enqueued_at time."""

    yield from enqueue_job(redis=redis, **stubs.job)
    utcparse((yield from redis.hget(job_key(stubs.job_id), 'enqueued_at')).decode())
示例#32
0
def test_enqueue_job_set_job_enqueued_at(redis):
    """Enqueue job must set enqueued_at time."""

    yield from enqueue_job(redis=redis, **stubs.job)
    utcparse((yield from redis.hget(job_key(stubs.job_id),
                                    'enqueued_at')).decode())
示例#33
0
def test_fail_job_sets_exc_info(redis):
    """Failed job should have exception information."""

    yield from fail_job(redis, stubs.queue, stubs.job_id, stubs.job_exc_info)
    exc_info = yield from redis.hget(job_key(stubs.job_id), 'exc_info')
    assert exc_info == stubs.job_exc_info.encode()
示例#34
0
def test_job_status(redis):
    """Get job status."""

    yield from redis.hset(job_key(stubs.job_id), 'status', JobStatus.QUEUED)
    assert (yield from job_status(redis, stubs.job_id)) == JobStatus.QUEUED.encode()
示例#35
0
def test_empty_removes_jobs(redis):
    """Emptying a queue deletes the associated job objects."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from empty_queue(redis, stubs.queue)
    assert not (yield from redis.exists(job_key(stubs.job_id)))
示例#36
0
def test_empty_removes_jobs(redis):
    """Emptying a queue deletes the associated job objects."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from empty_queue(redis, stubs.queue)
    assert not (yield from redis.exists(job_key(stubs.job_id)))