From 36b43f3edc4729bf1ffd1ada86bd7d40691edbd0 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 (cherry picked from commit 03b6b0a4ab36449efb94ce6cda65897b905f2bd0) --- 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 2c0b730b3..2f03941b3 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 @@ -145,7 +146,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 c765e1314..5ca88adec 100644 --- a/ironic_python_agent/tests/unit/test_inspector.py +++ b/ironic_python_agent/tests/unit/test_inspector.py @@ -199,6 +199,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() @@ -209,6 +210,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), @@ -222,6 +224,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),