Implement different connect strategy for zookeeper

Originally it was trying to connect during session_timeout time.
Such strategy doesn't work good during short network hiccups...
This commit is contained in:
Alexander Kukushkin
2016-07-01 12:31:29 +02:00
parent dc27a30800
commit f7c6bd4eab
2 changed files with 45 additions and 2 deletions
+13 -1
View File
@@ -3,9 +3,10 @@ import unittest
from kazoo.client import KazooState
from kazoo.exceptions import NoNodeError, NodeExistsError
from kazoo.handlers.threading import SequentialThreadingHandler
from kazoo.protocol.states import ZnodeStat
from mock import Mock, patch
from patroni.dcs.zookeeper import Leader, ZooKeeper, ZooKeeperError
from patroni.dcs.zookeeper import Leader, PatroniSequentialThreadingHandler, ZooKeeper, ZooKeeperError
class MockKazooClient(Mock):
@@ -92,6 +93,17 @@ class MockKazooClient(Mock):
raise NoNodeError
class TestPatroniSequentialThreadingHandler(unittest.TestCase):
def setUp(self):
self.handler = PatroniSequentialThreadingHandler(10)
@patch.object(SequentialThreadingHandler, 'create_connection', Mock())
def test_create_connection(self):
self.assertIsNotNone(self.handler.create_connection(()))
self.assertIsNotNone(self.handler.create_connection((), 40))
class TestZooKeeper(unittest.TestCase):
@patch('patroni.dcs.zookeeper.KazooClient', MockKazooClient)