Closes #1044. Fixing bug with mark_dead in connection pool
This commit is contained in:
@@ -65,7 +65,7 @@ class Connection(object):
|
|||||||
raise TypeError(
|
raise TypeError(
|
||||||
"Unsupported equality check for %s and %s" % (self, other)
|
"Unsupported equality check for %s and %s" % (self, other)
|
||||||
)
|
)
|
||||||
return True
|
return self.__hash__() == other.__hash__()
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return id(self)
|
return id(self)
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ class ConnectionPool(object):
|
|||||||
try:
|
try:
|
||||||
self.connections.remove(connection)
|
self.connections.remove(connection)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
logger.info("Attempted to remove %r, but it does not exist in the connection pool.", connection)
|
||||||
# connection not alive or another thread marked it already, ignore
|
# connection not alive or another thread marked it already, ignore
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from elasticsearch.connection_pool import (
|
|||||||
RoundRobinSelector,
|
RoundRobinSelector,
|
||||||
DummyConnectionPool,
|
DummyConnectionPool,
|
||||||
)
|
)
|
||||||
|
from elasticsearch.connection import Connection
|
||||||
from elasticsearch.exceptions import ImproperlyConfigured
|
from elasticsearch.exceptions import ImproperlyConfigured
|
||||||
|
|
||||||
from .test_cases import TestCase
|
from .test_cases import TestCase
|
||||||
@@ -72,6 +73,17 @@ class TestConnectionPool(TestCase):
|
|||||||
[pool.get_connection(), pool.get_connection(), pool.get_connection()],
|
[pool.get_connection(), pool.get_connection(), pool.get_connection()],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_new_connection_is_not_marked_dead(self):
|
||||||
|
# Create 10 connections
|
||||||
|
pool = ConnectionPool([(Connection(), {}) for _ in range(10)])
|
||||||
|
|
||||||
|
# Pass in a new connection that is not in the pool to mark as dead
|
||||||
|
new_connection = Connection()
|
||||||
|
pool.mark_dead(new_connection)
|
||||||
|
|
||||||
|
# Nothing should be marked dead
|
||||||
|
self.assertEquals(0, len(pool.dead_count))
|
||||||
|
|
||||||
def test_connection_is_forcibly_resurrected_when_no_live_ones_are_availible(self):
|
def test_connection_is_forcibly_resurrected_when_no_live_ones_are_availible(self):
|
||||||
pool = ConnectionPool([(x, {}) for x in range(2)])
|
pool = ConnectionPool([(x, {}) for x in range(2)])
|
||||||
pool.dead_count[0] = 1
|
pool.dead_count[0] = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user