mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-01-27 18:20:05 +00:00
Since a long time Patroni enforcing only one callback script running at a time. If the new callback is executed while the old one is still running, the old one is killed (including all child processes). Such behavior is fine for all callbacks but on_reload, because the last one may accidentally cancel important ones, that for example updating DNS or assigning/removing Virtual IP. To mitigate the problem we introduce a dedicated executor for on_reload callbacks, so that on_reload may only cancel another on_reload. Ref: https://github.com/zalando/patroni/issues/2445
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
import psutil
|
|
import unittest
|
|
|
|
from mock import Mock, patch
|
|
from patroni.postgresql.callback_executor import CallbackExecutor
|
|
|
|
|
|
class TestCallbackExecutor(unittest.TestCase):
|
|
|
|
@patch('psutil.Popen')
|
|
def test_callback_executor(self, mock_popen):
|
|
mock_popen.return_value.children.return_value = []
|
|
mock_popen.return_value.is_running.return_value = True
|
|
|
|
callback = ['test.sh', 'on_start', 'replica', 'foo']
|
|
ce = CallbackExecutor()
|
|
ce._kill_children = Mock(side_effect=Exception)
|
|
ce._invoke_excepthook = Mock()
|
|
self.assertIsNone(ce.call(callback))
|
|
ce.join()
|
|
|
|
self.assertIsNone(ce.call(callback))
|
|
|
|
mock_popen.return_value.kill.side_effect = psutil.AccessDenied()
|
|
self.assertIsNone(ce.call(callback))
|
|
|
|
ce._process_children = []
|
|
mock_popen.return_value.children.side_effect = psutil.Error()
|
|
mock_popen.return_value.kill.side_effect = psutil.NoSuchProcess(123)
|
|
self.assertIsNone(ce.call(callback))
|
|
|
|
mock_popen.side_effect = Exception
|
|
ce = CallbackExecutor()
|
|
ce._condition.wait = Mock(side_effect=[None, Exception])
|
|
ce._invoke_excepthook = Mock()
|
|
self.assertIsNone(ce.call(callback))
|
|
|
|
self.assertIsNone(ce.call(['test.sh', 'on_reload', 'replica', 'foo']))
|
|
ce.join()
|