Skip to content

Commit d49c0ba

Browse files
Garaz08avandras
authored andcommitted
Solve a couple of Flaky unit tests (patroni#3294)
1 parent bf5746e commit d49c0ba

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

tests/test_api.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,14 @@ def test_do_GET(self):
335335
'tag_key1=true&tag_key2=false&'
336336
'tag_key3=1&tag_key4=1.4&tag_key5=RandomTag&tag_key6=RandomTag2')
337337

338-
def test_do_OPTIONS(self):
338+
@patch.object(MockPatroni, 'dcs')
339+
def test_do_OPTIONS(self, mock_dcs):
340+
mock_dcs.cluster.status.last_lsn = 20
339341
self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'OPTIONS / HTTP/1.0'))
340342

341-
def test_do_HEAD(self):
343+
@patch.object(MockPatroni, 'dcs')
344+
def test_do_HEAD(self, mock_dcs):
345+
mock_dcs.cluster.status.last_lsn = 20
342346
self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'HEAD / HTTP/1.0'))
343347

344348
@patch.object(MockPatroni, 'dcs')

tests/test_kubernetes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def test_load_kube_config(self):
162162

163163

164164
@patch('urllib3.PoolManager.request')
165+
@patch.object(K8sConfig, '_server', '', create=True)
165166
class TestApiClient(unittest.TestCase):
166167

167168
@patch.object(K8sConfig, '_server', '', create=True)

tests/test_log.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ def test_patroni_logger(self):
8383
self.assertRaises(Exception, logger.shutdown)
8484
self.assertLessEqual(logger.queue_size, 2) # "Failed to close the old log handler" could be still in the queue
8585
self.assertEqual(logger.records_lost, 0)
86+
del config['log']['traceback_level']
87+
logger.reload_config(config)
8688

8789
def test_interceptor(self):
8890
logger = PatroniLogger()

tests/test_validator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,10 @@ def test_bin_dir_is_empty(self, mock_out, mock_err):
229229
c["kubernetes"]["pod_ip"] = "::1"
230230
c["consul"]["host"] = "127.0.0.1:50000"
231231
c["etcd"]["host"] = "127.0.0.1:237"
232-
c["postgresql"]["listen"] = "127.0.0.1:5432"
233232
with patch('patroni.validator.open', mock_open(read_data='9')):
234233
errors = schema(c)
235234
output = "\n".join(errors)
236-
self.assertEqual(['consul.host', 'etcd.host', 'postgresql.bin_dir', 'postgresql.data_dir', 'postgresql.listen',
235+
self.assertEqual(['consul.host', 'etcd.host', 'postgresql.bin_dir', 'postgresql.data_dir',
237236
'raft.bind_addr', 'raft.self_addr', 'restapi.connect_address'], parse_output(output))
238237

239238
def test_bin_dir_is_empty_string_executables_in_path(self, mock_out, mock_err):

0 commit comments

Comments
 (0)