Refactor tcp_keepalive code (#1578)

* Move it into a separate function
* set keepalive on the REST API socket

The function will be also used in #1162
This commit is contained in:
Alexander Kukushkin
2020-07-08 14:04:59 +02:00
committed by GitHub
parent 8eb01c77b6
commit 7a13579973
5 changed files with 59 additions and 19 deletions
+8 -1
View File
@@ -2,7 +2,7 @@ import unittest
from mock import Mock, patch
from patroni.exceptions import PatroniException
from patroni.utils import Retry, RetryFailedError, polling_loop, validate_directory
from patroni.utils import Retry, RetryFailedError, enable_keepalive, polling_loop, validate_directory
class TestUtils(unittest.TestCase):
@@ -33,6 +33,13 @@ class TestUtils(unittest.TestCase):
def test_validate_directory_is_not_a_directory(self):
self.assertRaises(PatroniException, validate_directory, "/tmp")
def test_enable_keepalive(self):
with patch('socket.SIO_KEEPALIVE_VALS', 1, create=True):
self.assertIsNotNone(enable_keepalive(Mock(), 10, 5))
for platform in ('linux2', 'darwin', 'other'):
with patch('sys.platform', platform):
self.assertIsNone(enable_keepalive(Mock(), 10, 5))
@patch('time.sleep', Mock())
class TestRetrySleeper(unittest.TestCase):