Files
patroni/tests/test_raft_controller.py
T
Alexander KukushkinandGitHub bfbc4860d5 PoC: Patroni on pure RAFT (#375)
* new node can join the cluster dynamically and become a part of consensus
 * it is also possible to join only Patroni cluster (without adding the node to the raft), just comment or remove `raft.self_addr` for that
 * when the node joins the cluster it is using values from `raft.partner_addrs` only for initial discovery.
* It is possible to run Patroni and Postgres on two nodes plus one node with `patroni_raft_controller` (without Patroni and Postgres). In such setup one can temporarily lose one node without affecting the primary.
2020-07-29 15:34:44 +02:00

47 lines
1.3 KiB
Python

import logging
import os
import unittest
from mock import Mock, patch
from pysyncobj import SyncObj
from patroni.config import Config
from patroni.raft_controller import RaftController, main as _main
from . import SleepException
class TestPatroniRaftController(unittest.TestCase):
SELF_ADDR = '127.0.0.1:5360'
def remove_files(self):
for f in ('journal', 'dump'):
f = self.SELF_ADDR + '.' + f
if os.path.exists(f):
os.unlink(f)
@patch('pysyncobj.tcp_server.TcpServer.bind', Mock())
def setUp(self):
self._handlers = logging.getLogger().handlers[:]
self.remove_files()
os.environ['PATRONI_RAFT_SELF_ADDR'] = self.SELF_ADDR
config = Config('postgres0.yml', validator=None)
self.rc = RaftController(config)
def tearDown(self):
logging.getLogger().handlers[:] = self._handlers
self.remove_files()
def test_reload_config(self):
self.rc.reload_config()
@patch('logging.Logger.error', Mock(side_effect=SleepException))
@patch.object(SyncObj, 'doTick', Mock(side_effect=Exception))
def test_run(self):
self.assertRaises(SleepException, self.rc.run)
self.rc.shutdown()
@patch('sys.argv', ['patroni'])
def test_patroni_raft_controller_main(self):
self.assertRaises(SystemExit, _main)