Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix'
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
Roguelazer committed Aug 22, 2017
2 parents 209b65c + f19db72 commit 2527f04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pystalk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,9 @@ def reserve_job(self, timeout=5):
:type timeout: int
"""
timeout = int(timeout)
if timeout >= self.socket_timeout:
raise ValueError('reserve_job timeout must be < socket timeout')
if self.socket_timeout is not None:
if timeout >= self.socket_timeout:
raise ValueError('reserve_job timeout must be < socket timeout')
if not self._watchlist:
raise ValueError('Select a tube or two before reserving a job')
with self._sock_ctx() as socket:
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from pystalk import BeanstalkError
import pystalk


def test_simple_flow(beanstalk_client, tube_name):
Expand Down Expand Up @@ -170,3 +171,20 @@ def test_using(beanstalk_client, tube_name):
def test_put_job_into(beanstalk_client, tube_name):
beanstalk_client.put_job_into(tube_name, 'some_job')
assert beanstalk_client.stats_tube(tube_name)['current-jobs-ready'] == 1


def test_socket_timeout(beanstalkd, tube_name):
host, port = beanstalkd
client = pystalk.BeanstalkClient(host, port, socket_timeout=10)
client.put_job_into(tube_name, 'some_job')
client.watch(tube_name)
with pytest.raises(ValueError):
client.reserve_job(timeout=11)
client.reserve_job(timeout=1)

def test_socket_timeout_none(beanstalkd, tube_name):
host, port = beanstalkd
client = pystalk.BeanstalkClient(host, port, socket_timeout=None)
client.put_job_into(tube_name, 'some_job')
client.watch(tube_name)
client.reserve_job(timeout=11)

0 comments on commit 2527f04

Please sign in to comment.