From 03b6b0a4ab36449efb94ce6cda65897b905f2bd0 Mon Sep 17 00:00:00 2001 From: Iury Gregory Melo Ferreira Date: Tue, 19 Dec 2023 14:26:59 -0300 Subject: [PATCH] Fix inspector retries to not take a long time Since we moved to exponential wait we increased the amount of time to run unit tests, now we can configure the max time to wait - before: Ran: 33 tests in 22.6581 sec. - after: Ran: 33 tests in 4.0256 sec. Change-Id: Ibdcfebacad0489d17183e43ceb0d603fce67e72b --- ironic_python_agent/inspector.py | 3 ++- ironic_python_agent/tests/unit/test_inspector.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ironic_python_agent/inspector.py b/ironic_python_agent/inspector.py index 9cfeb4e91..833592fe3 100644 --- a/ironic_python_agent/inspector.py +++ b/ironic_python_agent/inspector.py @@ -117,6 +117,7 @@ def inspect(): _RETRY_WAIT = 5 +_RETRY_WAIT_MAX = 30 _RETRY_ATTEMPTS = 5 @@ -138,7 +139,7 @@ def call_inspector(data, failures): requests.exceptions.HTTPError)), stop=tenacity.stop_after_attempt(_RETRY_ATTEMPTS), wait=tenacity.wait_exponential(multiplier=1.5, - min=_RETRY_WAIT, max=30), + min=_RETRY_WAIT, max=_RETRY_WAIT_MAX), reraise=True) def _post_to_inspector(): inspector_resp = requests.post( diff --git a/ironic_python_agent/tests/unit/test_inspector.py b/ironic_python_agent/tests/unit/test_inspector.py index cd5f2eae0..4143e938a 100644 --- a/ironic_python_agent/tests/unit/test_inspector.py +++ b/ironic_python_agent/tests/unit/test_inspector.py @@ -195,6 +195,7 @@ class TestCallInspector(base.IronicAgentTest): self.assertIsNone(res) @mock.patch.object(inspector, '_RETRY_WAIT', 0.01) + @mock.patch.object(inspector, '_RETRY_WAIT_MAX', 1) def test_inspector_retries(self, mock_post): mock_post.side_effect = requests.exceptions.ConnectionError failures = utils.AccumulatedFailures() @@ -205,6 +206,7 @@ class TestCallInspector(base.IronicAgentTest): self.assertEqual(5, mock_post.call_count) @mock.patch.object(inspector, '_RETRY_WAIT', 0.01) + @mock.patch.object(inspector, '_RETRY_WAIT_MAX', 1) @mock.patch.object(inspector, '_RETRY_ATTEMPTS', 3) def test_inspector_retries_on_50X_error(self, mock_post): mock_post.side_effect = [mock.Mock(status_code=500), @@ -218,6 +220,7 @@ class TestCallInspector(base.IronicAgentTest): self.assertEqual(3, mock_post.call_count) @mock.patch.object(inspector, '_RETRY_WAIT', 0.01) + @mock.patch.object(inspector, '_RETRY_WAIT_MAX', 1) @mock.patch.object(inspector, '_RETRY_ATTEMPTS', 2) def test_inspector_retry_on_50X_and_succeed(self, mock_post): mock_post.side_effect = [mock.Mock(status_code=503),