Solve a couple of Flaky unit tests (#3294)

This commit is contained in:
Garaz08
2025-02-25 15:39:46 +01:00
committed by GitHub
parent 1c5d9f5653
commit 92c4f9fbb5
4 changed files with 10 additions and 4 deletions

View File

@@ -329,10 +329,14 @@ class TestRestApiHandler(unittest.TestCase):
'tag_key1=true&tag_key2=false&'
'tag_key3=1&tag_key4=1.4&tag_key5=RandomTag&tag_key6=RandomTag2')
def test_do_OPTIONS(self):
@patch.object(MockPatroni, 'dcs')
def test_do_OPTIONS(self, mock_dcs):
mock_dcs.cluster.status.last_lsn = 20
self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'OPTIONS / HTTP/1.0'))
def test_do_HEAD(self):
@patch.object(MockPatroni, 'dcs')
def test_do_HEAD(self, mock_dcs):
mock_dcs.cluster.status.last_lsn = 20
self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'HEAD / HTTP/1.0'))
@patch.object(MockPatroni, 'dcs')

View File

@@ -161,6 +161,7 @@ class TestK8sConfig(unittest.TestCase):
@patch('urllib3.PoolManager.request')
@patch.object(K8sConfig, '_server', '', create=True)
class TestApiClient(unittest.TestCase):
@patch.object(K8sConfig, '_server', '', create=True)

View File

@@ -83,6 +83,8 @@ class TestPatroniLogger(unittest.TestCase):
self.assertRaises(Exception, logger.shutdown)
self.assertLessEqual(logger.queue_size, 2) # "Failed to close the old log handler" could be still in the queue
self.assertEqual(logger.records_lost, 0)
del config['log']['traceback_level']
logger.reload_config(config)
def test_interceptor(self):
logger = PatroniLogger()

View File

@@ -229,11 +229,10 @@ class TestValidator(unittest.TestCase):
c["kubernetes"]["pod_ip"] = "::1"
c["consul"]["host"] = "127.0.0.1:50000"
c["etcd"]["host"] = "127.0.0.1:237"
c["postgresql"]["listen"] = "127.0.0.1:5432"
with patch('patroni.validator.open', mock_open(read_data='9')):
errors = schema(c)
output = "\n".join(errors)
self.assertEqual(['consul.host', 'etcd.host', 'postgresql.bin_dir', 'postgresql.data_dir', 'postgresql.listen',
self.assertEqual(['consul.host', 'etcd.host', 'postgresql.bin_dir', 'postgresql.data_dir',
'raft.bind_addr', 'raft.self_addr', 'restapi.connect_address'], parse_output(output))
def test_bin_dir_is_empty_string_executables_in_path(self, mock_out, mock_err):