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'
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
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)
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)
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)
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)
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)
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"
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)
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)
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
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)
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, }
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, }
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'
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"
def test_kick_job(c: Client) -> None: id = c.put(b"a delayed job", delay=3600) c.kick_job(id) c.reserve(timeout=0)
def test_peek_buried_not_found(c: Client) -> None: c.put(b"a ready job") with pytest.raises(NotFoundError): c.peek_buried()
def test_max_job_size(c: Client) -> None: with pytest.raises(JobTooBigError): c.put(bytes(2 ** 16))
def test_binary_jobs(c: Client) -> None: data = os.urandom(4096) c.put(data) job = c.reserve() assert job.body == data
def test_peek(c: Client) -> None: id = c.put('job') job = c.peek(id) assert job.id == id assert job.body == 'job'
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"
def test_pause_tube(c: Client) -> None: c.put(b"") with assert_seconds(1): c.pause_tube("default", 1) c.reserve()
def test_peek_ready_not_found(c: Client) -> None: c.put(b"delayed", delay=10) with pytest.raises(NotFoundError): c.peek_ready()
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)
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"
def test_peek(c: Client) -> None: id = c.put(b"job") job = c.peek(id) assert job.id == id assert job.body == b"job"
def test_pause_tube(c: Client) -> None: c.put('') with assert_seconds(1): c.pause_tube('default', 1) c.reserve()