mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
It could happen that the WAL segment required for `pg_rewind` doesn't exist in the `pg_wal` anymore and therefore `pg_rewind` can't find the checkpoint location before the diverging point. Starting from PostgreSQL 13 `pg_rewind` could use `restore_command` for fetching missing WALs, but we can do better than that. On older PostgreSQL versions Patroni will parse the stdout and stderr of failed rewind attempt, try to fetch the missing WAL by calling the `restore_command`, and repeat an attempt.
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import psutil
|
|
import unittest
|
|
|
|
from mock import Mock, patch
|
|
from patroni.exceptions import PostgresException
|
|
from patroni.postgresql.cancellable import CancellableSubprocess
|
|
|
|
|
|
class TestCancellableSubprocess(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.c = CancellableSubprocess()
|
|
|
|
def test_call(self):
|
|
self.c.cancel()
|
|
self.assertRaises(PostgresException, self.c.call)
|
|
|
|
def test__kill_children(self):
|
|
self.c._process_children = [Mock()]
|
|
self.c._kill_children()
|
|
self.c._process_children[0].kill.side_effect = psutil.AccessDenied()
|
|
self.c._kill_children()
|
|
self.c._process_children[0].kill.side_effect = psutil.NoSuchProcess(123)
|
|
self.c._kill_children()
|
|
|
|
@patch('patroni.postgresql.cancellable.polling_loop', Mock(return_value=[0, 0]))
|
|
def test_cancel(self):
|
|
self.c._process = Mock()
|
|
self.c._process.is_running.return_value = True
|
|
self.c._process.children.side_effect = psutil.Error()
|
|
self.c._process.suspend.side_effect = psutil.Error()
|
|
self.c.cancel()
|
|
self.c._process.is_running.side_effect = [True, False]
|
|
self.c.cancel()
|