Fixed bugs caused by setting retry attempts to 0 on HashClient
This commit is contained in:
@@ -185,13 +185,13 @@ class HashClient(object):
|
|||||||
# dead immediately
|
# dead immediately
|
||||||
elif (
|
elif (
|
||||||
client.server not in self._failed_clients and
|
client.server not in self._failed_clients and
|
||||||
self.retry_attempts < 0
|
self.retry_attempts <= 0
|
||||||
):
|
):
|
||||||
self._failed_clients[client.server] = {
|
self._failed_clients[client.server] = {
|
||||||
'failed_time': time.time(),
|
'failed_time': time.time(),
|
||||||
'attempts': 0,
|
'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)
|
self.remove_server(*client.server)
|
||||||
# This client has failed previously, we need to update the metadata
|
# This client has failed previously, we need to update the metadata
|
||||||
# to reflect that we have attempted it again
|
# to reflect that we have attempted it again
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from .test_client import ClientTestMixin, MockSocket
|
|||||||
import unittest
|
import unittest
|
||||||
import pytest
|
import pytest
|
||||||
import mock
|
import mock
|
||||||
|
import socket
|
||||||
|
|
||||||
|
|
||||||
class TestHashClient(ClientTestMixin, unittest.TestCase):
|
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'
|
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):
|
def test_no_servers_left_with_commands(self):
|
||||||
from pymemcache.client.hash import HashClient
|
from pymemcache.client.hash import HashClient
|
||||||
client = HashClient(
|
client = HashClient(
|
||||||
|
|||||||
Reference in New Issue
Block a user