Windows compatibility fixes (#1633)

* pg_rewind error messages contain '/' as directory separator
* fix Raft unit tests on win
* fix validator unit tests on win
* fix keepalive unit tests on win
* make standby cluster behave tests less shaky
This commit is contained in:
Alexander Kukushkin
2020-07-31 15:43:50 +02:00
committed by GitHub
parent d4c6987f78
commit f1c6b0bebe
6 changed files with 29 additions and 17 deletions
+1
View File
@@ -25,6 +25,7 @@ Feature: standby cluster
Then postgres1 is a leader of batman1 after 10 seconds Then postgres1 is a leader of batman1 after 10 seconds
When I add the table foo to postgres0 When I add the table foo to postgres0
Then table foo is present on postgres1 after 20 seconds Then table foo is present on postgres1 after 20 seconds
And I sleep for 3 seconds
When I issue a GET request to http://127.0.0.1:8009/master When I issue a GET request to http://127.0.0.1:8009/master
Then I receive a response code 503 Then I receive a response code 503
When I issue a GET request to http://127.0.0.1:8009/standby_leader When I issue a GET request to http://127.0.0.1:8009/standby_leader
+3 -3
View File
@@ -283,9 +283,9 @@ class Rewind(object):
if b > -1: if b > -1:
b += len(pattern) b += len(pattern)
e = line.find('": ', b) e = line.find('": ', b)
if e > -1: if e > -1 and '/' in line[b:e]:
waldir, wal_filename = os.path.split(line[b:e]) waldir, wal_filename = line[b:e].rsplit('/', 1)
if waldir.endswith(os.path.sep + 'pg_' + self._postgresql.wal_name) and len(wal_filename) == 24: if waldir.endswith('/pg_' + self._postgresql.wal_name) and len(wal_filename) == 24:
return wal_filename return wal_filename
def pg_rewind(self, r): def pg_rewind(self, r):
+18 -7
View File
@@ -7,6 +7,21 @@ from patroni.dcs.raft import DynMemberSyncObj, KVStoreTTL, Raft, SyncObjUtility
from pysyncobj import SyncObjConf, FAIL_REASON from pysyncobj import SyncObjConf, FAIL_REASON
def remove_files(prefix):
for f in ('journal', 'dump'):
f = prefix + f
if os.path.isfile(f):
for i in range(0, 15):
try:
if os.path.isfile(f):
os.unlink(f)
break
else:
break
except Exception:
time.sleep(1.0)
@patch('pysyncobj.tcp_server.TcpServer.bind', Mock()) @patch('pysyncobj.tcp_server.TcpServer.bind', Mock())
class TestDynMemberSyncObj(unittest.TestCase): class TestDynMemberSyncObj(unittest.TestCase):
@@ -44,7 +59,7 @@ class TestDynMemberSyncObj(unittest.TestCase):
class TestKVStoreTTL(unittest.TestCase): class TestKVStoreTTL(unittest.TestCase):
def setUp(self): def setUp(self):
self.conf = SyncObjConf(appendEntriesUseBatch=False, appendEntriesPeriod=0.001, journalFile='foo.journal', self.conf = SyncObjConf(appendEntriesUseBatch=False, appendEntriesPeriod=0.001,
raftMinTimeout=0.004, raftMaxTimeout=0.005, autoTickPeriod=0.001) raftMinTimeout=0.004, raftMaxTimeout=0.005, autoTickPeriod=0.001)
callback = Mock() callback = Mock()
callback.replicated = False callback.replicated = False
@@ -59,8 +74,6 @@ class TestKVStoreTTL(unittest.TestCase):
def tearDown(self): def tearDown(self):
if self.so: if self.so:
self.destroy(self.so) self.destroy(self.so)
if os.path.exists('foo.journal'):
os.unlink('foo.journal')
def test_set(self): def test_set(self):
self.assertTrue(self.so.set('foo', 'bar', prevExist=False, ttl=30)) self.assertTrue(self.so.set('foo', 'bar', prevExist=False, ttl=30))
@@ -69,6 +82,7 @@ class TestKVStoreTTL(unittest.TestCase):
self.assertTrue(self.so.retry(self.so._set, 'foo', {'value': 'buz', 'created': 1, 'updated': 1})) self.assertTrue(self.so.retry(self.so._set, 'foo', {'value': 'buz', 'created': 1, 'updated': 1}))
def test_delete(self): def test_delete(self):
self.conf.autoTickPeriod = 0.1
self.so.set('foo', 'bar') self.so.set('foo', 'bar')
self.so.set('fooo', 'bar') self.so.set('fooo', 'bar')
self.assertFalse(self.so.delete('foo', prevValue='buz')) self.assertFalse(self.so.delete('foo', prevValue='buz'))
@@ -128,10 +142,7 @@ class TestRaft(unittest.TestCase):
raft._sync_obj._SyncObj__thread.join() raft._sync_obj._SyncObj__thread.join()
def tearDown(self): def tearDown(self):
for f in ('journal', 'dump'): remove_files('127.0.0.1:1234.')
f = '127.0.0.1:1234.' + f
if os.path.exists(f):
os.unlink(f)
def setUp(self): def setUp(self):
self.tearDown() self.tearDown()
+2 -4
View File
@@ -8,6 +8,7 @@ from patroni.config import Config
from patroni.raft_controller import RaftController, main as _main from patroni.raft_controller import RaftController, main as _main
from . import SleepException from . import SleepException
from .test_raft import remove_files
class TestPatroniRaftController(unittest.TestCase): class TestPatroniRaftController(unittest.TestCase):
@@ -15,10 +16,7 @@ class TestPatroniRaftController(unittest.TestCase):
SELF_ADDR = '127.0.0.1:5360' SELF_ADDR = '127.0.0.1:5360'
def remove_files(self): def remove_files(self):
for f in ('journal', 'dump'): remove_files(self.SELF_ADDR + '.')
f = self.SELF_ADDR + '.' + f
if os.path.exists(f):
os.unlink(f)
@patch('pysyncobj.tcp_server.TcpServer.bind', Mock()) @patch('pysyncobj.tcp_server.TcpServer.bind', Mock())
def setUp(self): def setUp(self):
+4 -3
View File
@@ -36,9 +36,10 @@ class TestUtils(unittest.TestCase):
def test_enable_keepalive(self): def test_enable_keepalive(self):
with patch('socket.SIO_KEEPALIVE_VALS', 1, create=True): with patch('socket.SIO_KEEPALIVE_VALS', 1, create=True):
self.assertIsNotNone(enable_keepalive(Mock(), 10, 5)) self.assertIsNotNone(enable_keepalive(Mock(), 10, 5))
for platform in ('linux2', 'darwin', 'other'): with patch('socket.SIO_KEEPALIVE_VALS', None, create=True):
with patch('sys.platform', platform): for platform in ('linux2', 'darwin', 'other'):
self.assertIsNone(enable_keepalive(Mock(), 10, 5)) with patch('sys.platform', platform):
self.assertIsNone(enable_keepalive(Mock(), 10, 5))
@patch('time.sleep', Mock()) @patch('time.sleep', Mock())
+1
View File
@@ -153,6 +153,7 @@ class TestValidator(unittest.TestCase):
self.assertEqual(['etcd.hosts.1', 'etcd.hosts.2', 'kubernetes.pod_ip', 'postgresql.bin_dir', self.assertEqual(['etcd.hosts.1', 'etcd.hosts.2', 'kubernetes.pod_ip', 'postgresql.bin_dir',
'postgresql.data_dir', 'restapi.connect_address'], parse_output(output)) 'postgresql.data_dir', 'restapi.connect_address'], parse_output(output))
@patch('socket.inet_pton', Mock(), create=True)
def test_bin_dir_is_empty(self, mock_out, mock_err): def test_bin_dir_is_empty(self, mock_out, mock_err):
directories.append(config["postgresql"]["data_dir"]) directories.append(config["postgresql"]["data_dir"])
directories.append(config["postgresql"]["bin_dir"]) directories.append(config["postgresql"]["bin_dir"])