Fixed bugs caused by setting retry attempts to 0 on HashClient

This commit is contained in:
Remco van Oosterhout
2015-10-21 12:33:52 +00:00
parent 37e458e692
commit 8161f4a818
2 changed files with 14 additions and 2 deletions

View File

@@ -185,13 +185,13 @@ class HashClient(object):
# dead immediately
elif (
client.server not in self._failed_clients and
self.retry_attempts < 0
self.retry_attempts <= 0
):
self._failed_clients[client.server] = {
'failed_time': time.time(),
'attempts': 0,
}
logger.debug("marking server as dead %s" % client.server)
logger.debug("marking server as dead %s", client.server)
self.remove_server(*client.server)
# This client has failed previously, we need to update the metadata
# to reflect that we have attempted it again

View File

@@ -7,6 +7,7 @@ from .test_client import ClientTestMixin, MockSocket
import unittest
import pytest
import mock
import socket
class TestHashClient(ClientTestMixin, unittest.TestCase):
@@ -144,6 +145,17 @@ class TestHashClient(ClientTestMixin, unittest.TestCase):
assert str(e.value) == 'All servers seem to be down right now'
def test_unavailable_servers_zero_retry_raise_exception(self):
from pymemcache.client.hash import HashClient
client = HashClient(
[('example.com', 11211)], use_pooling=True,
ignore_exc=False,
retry_attempts=0, timeout=1, connect_timeout=1
)
with pytest.raises(socket.error) as e:
client.get('foo')
def test_no_servers_left_with_commands(self):
from pymemcache.client.hash import HashClient
client = HashClient(