Skip to content

Commit 9fccae1

Browse files
committed
Merge pull request jplana#135 from projectcalico/smc-fix-read-timeout-err
Introduce EtcdWatchTimedOut exception.
2 parents df6caa9 + ee601e9 commit 9fccae1

5 files changed

Lines changed: 33 additions & 2 deletions

File tree

buildout.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ parts = python
44
test
55
develop = .
66
eggs =
7-
urllib3==1.7
7+
urllib3==1.7.1
88
pyOpenSSL==0.13.1
99

1010
[python]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
version = '0.4.2'
1010

1111
install_requires = [
12-
'urllib3>=1.7'
12+
'urllib3>=1.7.1'
1313
]
1414

1515
test_requires = [

src/etcd/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ def __init__(self, message=None, payload=None, cause=None):
200200
self.cause = cause
201201

202202

203+
class EtcdWatchTimedOut(EtcdConnectionFailed):
204+
"""
205+
A watch timed out without returning a result.
206+
"""
207+
pass
208+
209+
203210
class EtcdWatcherCleared(EtcdException):
204211
"""
205212
Watcher is cleared due to etcd recovery.

src/etcd/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,14 @@ def api_execute(self, path, method, params=None, timeout=None):
772772
except (urllib3.exceptions.HTTPError,
773773
HTTPException,
774774
socket.error) as e:
775+
if (params.get("wait") == "true" and
776+
isinstance(e, urllib3.exceptions.ReadTimeoutError)):
777+
_log.debug("Watch timed out.")
778+
raise etcd.EtcdWatchTimedOut(
779+
"Watch timed out: %r" % e,
780+
cause=e
781+
)
782+
775783
_log.error("Request to server %s failed: %r",
776784
self._base_uri, e)
777785
if self._allow_reconnect:

src/etcd/tests/unit/test_request.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import urllib3
2+
13
import etcd
24
from etcd.tests.unit import TestClientApiBase
35

@@ -428,6 +430,20 @@ def test_compare_and_swap_failure(self):
428430
prevValue='oldbog'
429431
)
430432

433+
def test_watch_timeout(self):
434+
""" Exception will be raised if prevValue != value in test_set """
435+
self.client.http.request = mock.create_autospec(
436+
self.client.http.request,
437+
side_effect=urllib3.exceptions.ReadTimeoutError(self.client.http,
438+
"foo",
439+
"Read timed out")
440+
)
441+
self.assertRaises(
442+
etcd.EtcdWatchTimedOut,
443+
self.client.watch,
444+
'/testKey',
445+
)
446+
431447
def test_path_without_trailing_slash(self):
432448
""" Exception will be raised if a path without a trailing slash is used """
433449
self.assertRaises(ValueError, self.client.api_execute,

0 commit comments

Comments
 (0)