mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-01-27 18:20:05 +00:00
Old versions of `kazoo` immediately discarded all requests to Zookeeper if the connection is in the `SUSPENDED` state. This is absolutely fine because Patroni is handling retries on its own. Starting from 2.7, kazoo started queueing requests instead of discarding and as a result, the Patroni HA loop was getting stuck until the connection to Zookeeper is reestablished, causing no demote of the Postgres. In order to return to the old behavior we override the `KazooClient._call()` method. In addition to that, we ensure that the `Postgresql.reset_cluster_info_state()` method is called even if DCS failed (the order of calls was changed in the #1820). Close https://github.com/zalando/patroni/issues/1981
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
import unittest
|
|
import urllib3
|
|
|
|
from mock import Mock, patch
|
|
from patroni.dcs.exhibitor import ExhibitorEnsembleProvider, Exhibitor
|
|
from patroni.dcs.zookeeper import ZooKeeperError
|
|
|
|
from . import SleepException, requests_get
|
|
from .test_zookeeper import MockKazooClient
|
|
|
|
|
|
@patch('patroni.dcs.exhibitor.requests_get', requests_get)
|
|
@patch('time.sleep', Mock(side_effect=SleepException))
|
|
class TestExhibitorEnsembleProvider(unittest.TestCase):
|
|
|
|
def test_init(self):
|
|
self.assertRaises(SleepException, ExhibitorEnsembleProvider, ['localhost'], 8181)
|
|
|
|
def test_poll(self):
|
|
self.assertFalse(ExhibitorEnsembleProvider(['exhibitor'], 8181).poll())
|
|
|
|
|
|
class TestExhibitor(unittest.TestCase):
|
|
|
|
@patch('urllib3.PoolManager.request', Mock(return_value=urllib3.HTTPResponse(
|
|
status=200, body=b'{"servers":["127.0.0.1","127.0.0.2","127.0.0.3"],"port":2181}')))
|
|
@patch('patroni.dcs.zookeeper.PatroniKazooClient', MockKazooClient)
|
|
def setUp(self):
|
|
self.e = Exhibitor({'hosts': ['localhost', 'exhibitor'], 'port': 8181, 'scope': 'test',
|
|
'name': 'foo', 'ttl': 30, 'retry_timeout': 10})
|
|
|
|
@patch.object(ExhibitorEnsembleProvider, 'poll', Mock(return_value=True))
|
|
def test_get_cluster(self):
|
|
self.assertRaises(ZooKeeperError, self.e.get_cluster)
|