From ee49fb654f9aaf8fe623a34d415e1de700f86911 Mon Sep 17 00:00:00 2001 From: James Brown Date: Tue, 22 Aug 2017 09:32:32 -0700 Subject: [PATCH 1/2] allow socket_timeout to be None --- pystalk/client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pystalk/client.py b/pystalk/client.py index e73f16e..dc803e8 100644 --- a/pystalk/client.py +++ b/pystalk/client.py @@ -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: From f19db72dbf64309ed28770960a08a68efb5e582f Mon Sep 17 00:00:00 2001 From: James Brown Date: Tue, 22 Aug 2017 15:49:03 -0700 Subject: [PATCH 2/2] add regression tests --- tests/integration/test_basic.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/integration/test_basic.py b/tests/integration/test_basic.py index f1b62fb..38d9d2d 100644 --- a/tests/integration/test_basic.py +++ b/tests/integration/test_basic.py @@ -1,6 +1,7 @@ import pytest from pystalk import BeanstalkError +import pystalk def test_simple_flow(beanstalk_client, tube_name): @@ -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)