Example #1
0
def test_put_priority(c: Client) -> None:
    c.put('2', priority=2)
    c.put('1', priority=1)
    job = c.reserve()
    assert job.body == '1'
    job = c.reserve()
    assert job.body == '2'
Example #2
0
def test_str_body_no_encoding() -> None:
    class Fake:
        def __init__(self) -> None:
            self.encoding = None

    with pytest.raises(TypeError):
        Client.put(Fake(), 'a str job')  # type: ignore
Example #3
0
def test_delete_job_reserved_by_other(c: Client) -> None:
    c.put('', ttr=1)
    other = Client(port=PORT)
    job = other.reserve()
    with pytest.raises(NotFoundError):
        c.delete(job)
    time.sleep(1)
    c.delete(job)
Example #4
0
def test_initialize_with_tubes(c: Client) -> None:
    c.put(b"www.example.com")
    job = c.reserve()
    assert job.body == b"www.example.com"
    c.delete(job.id)
    c.use("default")
    c.put(b"")
    with pytest.raises(TimedOutError):
        c.reserve(timeout=0)
Example #5
0
def test_initialize_with_tubes(c: Client) -> None:
    c.put('www.example.com')
    job = c.reserve()
    assert job.body == 'www.example.com'
    c.delete(job.id)
    c.use('default')
    c.put('')
    with pytest.raises(TimedOutError):
        c.reserve(timeout=0)
Example #6
0
def test_ttr(c: Client) -> None:
    c.put(b"two second ttr", ttr=2)
    with assert_seconds(1):
        job = c.reserve()
        with pytest.raises(DeadlineSoonError):
            c.reserve()
    with assert_seconds(1):
        c.touch(job)
        with pytest.raises(DeadlineSoonError):
            c.reserve()
    c.release(job)
Example #7
0
def test_delays(c: Client) -> None:
    with assert_seconds(1):
        c.put(b"delayed", delay=1)
        job = c.reserve()
        assert job.body == b"delayed"
    with assert_seconds(2):
        c.release(job, delay=2)
        with pytest.raises(TimedOutError):
            c.reserve(timeout=1)
        job = c.reserve(timeout=1)
    c.bury(job)
    with pytest.raises(TimedOutError):
        c.reserve(timeout=0)
Example #8
0
def test_peek_buried(c: Client) -> None:
    id = c.put(b"buried")
    job = c.reserve()
    c.bury(job)
    job = c.peek_buried()
    assert job.id == id
    assert job.body == b"buried"
Example #9
0
def test_basic_usage(c: Client) -> None:
    c.use("emails")
    id = c.put("测试@example.com".encode("utf-8"))
    c.watch("emails")
    c.ignore("default")
    job = c.reserve()
    assert id == job.id
    assert job.body.decode("utf-8") == "测试@example.com"
    c.delete(job)
Example #10
0
def test_basic_usage(c: Client) -> None:
    c.use('emails')
    id = c.put('测试@example.com')
    c.watch('emails')
    c.ignore('default')
    job = c.reserve()
    assert id == job.id
    assert job.body == '测试@example.com'
    c.delete(job)
Example #11
0
def test_kick(c: Client) -> None:
    c.put(b"a delayed job", delay=30)
    c.put(b"another delayed job", delay=45)
    c.put(b"a ready job")
    job = c.reserve()
    c.bury(job)
    assert c.kick(10) == 1
    assert c.kick(10) == 2
Example #12
0
def test_reserve_job(c: Client) -> None:
    id1 = c.put(b"a")
    id2 = c.put(b"b")
    j1 = c.reserve_job(id1)
    j2 = c.reserve_job(id2)
    with pytest.raises(NotFoundError):
        c.reserve_job(id1)
    with pytest.raises(NotFoundError):
        c.reserve_job(id2)
    with pytest.raises(TimedOutError):
        c.reserve(timeout=0)
    c.delete(j1)
    c.delete(j2)
    with pytest.raises(TimedOutError):
        c.reserve(timeout=0)
Example #13
0
def test_stats_job(c: Client) -> None:
    assert c.stats_job(c.put('job')) == {
        'id': 1,
        'tube': 'default',
        'state': 'ready',
        'pri': DEFAULT_PRIORITY,
        'age': 0,
        'delay': 0,
        'ttr': DEFAULT_TTR,
        'time-left': 0,
        'file': 0,
        'reserves': 0,
        'timeouts': 0,
        'releases': 0,
        'buries': 0,
        'kicks': 0,
    }
Example #14
0
def test_stats_job(c: Client) -> None:
    assert c.stats_job(c.put(b"job")) == {
        "id": 1,
        "tube": "default",
        "state": "ready",
        "pri": DEFAULT_PRIORITY,
        "age": 0,
        "delay": 0,
        "ttr": DEFAULT_TTR,
        "time-left": 0,
        "file": 0,
        "reserves": 0,
        "timeouts": 0,
        "releases": 0,
        "buries": 0,
        "kicks": 0,
    }
Example #15
0
def test_initialize_watch_multiple(c: Client) -> None:
    c.use('static')
    c.put(b'haskell')
    c.put(b'rust')
    c.use('dynamic')
    c.put(b'python')
    job = c.reserve(timeout=0)
    assert job.body == 'haskell'
    job = c.reserve(timeout=0)
    assert job.body == 'rust'
    job = c.reserve(timeout=0)
    assert job.body == 'python'
Example #16
0
def test_initialize_watch_multiple(c: Client) -> None:
    c.use("static")
    c.put(b"haskell")
    c.put(b"rust")
    c.use("dynamic")
    c.put(b"python")
    job = c.reserve(timeout=0)
    assert job.body == b"haskell"
    job = c.reserve(timeout=0)
    assert job.body == b"rust"
    job = c.reserve(timeout=0)
    assert job.body == b"python"
Example #17
0
def test_kick_job(c: Client) -> None:
    id = c.put(b"a delayed job", delay=3600)
    c.kick_job(id)
    c.reserve(timeout=0)
Example #18
0
def test_peek_buried_not_found(c: Client) -> None:
    c.put(b"a ready job")
    with pytest.raises(NotFoundError):
        c.peek_buried()
Example #19
0
def test_max_job_size(c: Client) -> None:
    with pytest.raises(JobTooBigError):
        c.put(bytes(2 ** 16))
Example #20
0
def test_binary_jobs(c: Client) -> None:
    data = os.urandom(4096)
    c.put(data)
    job = c.reserve()
    assert job.body == data
Example #21
0
def test_peek(c: Client) -> None:
    id = c.put('job')
    job = c.peek(id)
    assert job.id == id
    assert job.body == 'job'
Example #22
0
def test_peek_ready(c: Client) -> None:
    id = c.put(b"ready")
    job = c.peek_ready()
    assert job.id == id
    assert job.body == b"ready"
Example #23
0
def test_pause_tube(c: Client) -> None:
    c.put(b"")
    with assert_seconds(1):
        c.pause_tube("default", 1)
        c.reserve()
Example #24
0
def test_peek_ready_not_found(c: Client) -> None:
    c.put(b"delayed", delay=10)
    with pytest.raises(NotFoundError):
        c.peek_ready()
Example #25
0
def test_delete_job_reserved_by_other(c: Client) -> None:
    c.put(b"", ttr=1)
    with Client(DEFAULT_INET_ADDRESS) as other:
        job = other.reserve()
        with pytest.raises(NotFoundError):
            c.delete(job)
Example #26
0
def test_peek_delayed(c: Client) -> None:
    id = c.put(b"delayed", delay=10)
    job = c.peek_delayed()
    assert job.id == id
    assert job.body == b"delayed"
Example #27
0
def test_peek(c: Client) -> None:
    id = c.put(b"job")
    job = c.peek(id)
    assert job.id == id
    assert job.body == b"job"
Example #28
0
def test_pause_tube(c: Client) -> None:
    c.put('')
    with assert_seconds(1):
        c.pause_tube('default', 1)
        c.reserve()