From 6c1f2c40a9531e2fff318d5cdfdc2bb128186897 Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Neppel Date: Mon, 8 Jul 2024 16:15:39 -0300 Subject: [PATCH] Update test_update_synchronous_node_count Signed-off-by: Marcelo Henrique Neppel --- tests/unit/test_cluster.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_cluster.py b/tests/unit/test_cluster.py index 4b2001475a..1bc30dde9b 100644 --- a/tests/unit/test_cluster.py +++ b/tests/unit/test_cluster.py @@ -10,7 +10,7 @@ from charms.operator_libs_linux.v2 import snap from jinja2 import Template from ops.testing import Harness -from tenacity import stop_after_delay +from tenacity import RetryError, stop_after_delay, wait_fixed from charm import PostgresqlOperatorCharm from cluster import Patroni @@ -429,7 +429,9 @@ def test_switchover(peers_ips, patroni): def test_update_synchronous_node_count(peers_ips, patroni): - with patch("requests.patch") as _patch: + with patch("cluster.stop_after_delay", return_value=stop_after_delay(0)) as _wait_fixed, patch( + "cluster.wait_fixed", return_value=wait_fixed(0) + ) as _wait_fixed, patch("requests.patch") as _patch: response = _patch.return_value response.status_code = 200 @@ -439,6 +441,11 @@ def test_update_synchronous_node_count(peers_ips, patroni): "http://1.1.1.1:8008/config", json={"synchronous_node_count": 0}, verify=True ) + # Test when the request fails. + response.status_code = 500 + with tc.assertRaises(RetryError): + patroni.update_synchronous_node_count() + def test_configure_patroni_on_unit(peers_ips, patroni): with (