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
This commit is contained in:
Iury Gregory Melo Ferreira 2023-12-19 14:26:59 -03:00
parent 3a757f721f
commit 03b6b0a4ab
2 changed files with 5 additions and 1 deletions

View File

@ -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(

View File

@ -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),