Пример #1
0
def test_put_priority(c: Client) -> None:
    c.put(b"2", priority=2)
    c.put(b"1", priority=1)
    job = c.reserve()
    assert job.body == b"1"
    job = c.reserve()
    assert job.body == b"2"
Пример #2
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'
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
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'
Пример #7
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"
Пример #8
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)
Пример #9
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"
Пример #10
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
Пример #11
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)
Пример #12
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)
Пример #13
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)
Пример #14
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)
Пример #15
0
def test_binary_jobs(c: Client) -> None:
    data = os.urandom(4096)
    c.put(data)
    job = c.reserve()
    assert job.body == data
Пример #16
0
def test_pause_tube(c: Client) -> None:
    c.put(b"")
    with assert_seconds(1):
        c.pause_tube("default", 1)
        c.reserve()
Пример #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)
Пример #18
0
def test_pause_tube(c: Client) -> None:
    c.put('')
    with assert_seconds(1):
        c.pause_tube('default', 1)
        c.reserve()
Пример #19
0
def test_reserve_raises_on_timeout(c: Client) -> None:
    with assert_seconds(1):
        with pytest.raises(TimedOutError):
            c.reserve(timeout=1)