From 92c4f9fbb5efd2007b4ac959d658a64ba1ec2f61 Mon Sep 17 00:00:00 2001 From: Garaz08 <86228935+Garaz08@users.noreply.github.com> Date: Tue, 25 Feb 2025 15:39:46 +0100 Subject: [PATCH] Solve a couple of Flaky unit tests (#3294) --- tests/test_api.py | 8 ++++++-- tests/test_kubernetes.py | 1 + tests/test_log.py | 2 ++ tests/test_validator.py | 3 +-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index 68091f9e..92641a1f 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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') diff --git a/tests/test_kubernetes.py b/tests/test_kubernetes.py index b2cb95a4..a32c348a 100644 --- a/tests/test_kubernetes.py +++ b/tests/test_kubernetes.py @@ -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) diff --git a/tests/test_log.py b/tests/test_log.py index dbc4ec19..9d7b412f 100644 --- a/tests/test_log.py +++ b/tests/test_log.py @@ -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() diff --git a/tests/test_validator.py b/tests/test_validator.py index 8ee18815..8bcd5437 100644 --- a/tests/test_validator.py +++ b/tests/test_validator.py @@ -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):