Closes #1044. Fixing bug with mark_dead in connection pool

This commit is contained in:
Alex Kahan
2019-10-29 17:01:47 +01:00
committed by Honza Král
parent fc78c992ef
commit a2e9f0c807
3 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ class Connection(object):
raise TypeError(
"Unsupported equality check for %s and %s" % (self, other)
)
return True
return self.__hash__() == other.__hash__()
def __hash__(self):
return id(self)
+1
View File
@@ -150,6 +150,7 @@ class ConnectionPool(object):
try:
self.connections.remove(connection)
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
return
else:
@@ -5,6 +5,7 @@ from elasticsearch.connection_pool import (
RoundRobinSelector,
DummyConnectionPool,
)
from elasticsearch.connection import Connection
from elasticsearch.exceptions import ImproperlyConfigured
from .test_cases import TestCase
@@ -72,6 +73,17 @@ class TestConnectionPool(TestCase):
[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):
pool = ConnectionPool([(x, {}) for x in range(2)])
pool.dead_count[0] = 1