From ce7169f61df109427ec723519d24773bddc1b6fb Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Mon, 12 Oct 2015 15:29:47 +0200 Subject: [PATCH] Add new tests ha and postgresql. --- tests/test_ha.py | 1 + tests/test_postgresql.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_ha.py b/tests/test_ha.py index c55cbd90..38bb07a6 100644 --- a/tests/test_ha.py +++ b/tests/test_ha.py @@ -117,6 +117,7 @@ class TestHa(unittest.TestCase): self.assertEquals(self.ha.run_cycle(), 'started as a secondary') def test_recover_replica_failed(self): + self.p.controldata = lambda: {'Database cluster state': 'in production'} self.p.is_healthy = false self.p.follow_the_leader = false self.assertEquals(self.ha.run_cycle(), 'failed to start postgres') diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 0be4317e..060302c7 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -10,7 +10,7 @@ if version_info.major == 2: else: import builtins -from mock import Mock, MagicMock, patch +from mock import Mock, MagicMock, PropertyMock, patch from patroni.dcs import Cluster, Leader, Member from patroni.exceptions import PostgresException, PostgresConnectionException from patroni.postgresql import Postgresql @@ -216,7 +216,6 @@ class TestPostgresql(unittest.TestCase): @patch('subprocess.call', side_effect=Exception("Test")) def test_pg_rewind(self, mock_call): self.assertTrue(self.p.rewind(self.leader)) - self.p subprocess.call = mock_call self.assertFalse(self.p.rewind(self.leader)) @@ -230,6 +229,12 @@ class TestPostgresql(unittest.TestCase): self.p.follow_the_leader(Leader(-1, 28, self.other)) self.p.rewind = mock_pg_rewind self.p.follow_the_leader(self.leader) + self.p.require_rewind() + with mock.patch('patroni.postgresql.Postgresql.can_rewind', new_callable=PropertyMock(return_value=True)): + self.p.rewind.return_value = True + self.p.follow_the_leader(self.leader, recovery=True) + self.p.rewind.return_value = False + self.p.follow_the_leader(self.leader, recovery=True) def test_create_replica(self): self.p.delete_trigger_file = Mock(side_effect=OSError())