base_adresse: retry on 504 and reduce to 3 short retries (#74397)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
f914b8542a
commit
b5995828a5
|
@ -69,8 +69,10 @@ class BaseAdresse(AddressResource):
|
|||
|
||||
requests_timeout = 1
|
||||
requests_max_retries = {
|
||||
'total': 5,
|
||||
'backoff_factor': 1,
|
||||
'total': 3,
|
||||
'backoff_factor': 0.5,
|
||||
# retry after: 0.5, 1.5 and 3.5 seconds
|
||||
'status_forcelist': [413, 429, 503, 504],
|
||||
}
|
||||
|
||||
def sectorize(self, address):
|
||||
|
|
|
@ -5,9 +5,11 @@ from unittest import mock
|
|||
from urllib.parse import parse_qs, urljoin
|
||||
|
||||
import pytest
|
||||
import responses
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import CommandError
|
||||
from requests.exceptions import ConnectionError, HTTPError
|
||||
from responses.registries import OrderedRegistry
|
||||
|
||||
import tests.utils
|
||||
from passerelle.apps.base_adresse.models import (
|
||||
|
@ -1125,3 +1127,75 @@ def test_base_adresse_reverse_cache(
|
|||
assert mock_api_adresse_data_gouv_fr_search.call['count'] == 1
|
||||
assert data['id'] != api_id
|
||||
assert data['id'] == api_id.lower()
|
||||
|
||||
|
||||
@responses.activate(registry=OrderedRegistry) # pylint: disable=unexpected-keyword-arg,no-value-for-parameter
|
||||
def test_base_adresse_search_retry(app, base_adresse):
|
||||
from passerelle.utils import Request
|
||||
|
||||
Request.ADAPTER_REGISTRY.clear()
|
||||
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'https://api-adresse.data.gouv.fr/search/',
|
||||
body='Error',
|
||||
status=504,
|
||||
)
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'https://api-adresse.data.gouv.fr/search/',
|
||||
body='Error',
|
||||
status=504,
|
||||
)
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'https://api-adresse.data.gouv.fr/search/',
|
||||
body='Error',
|
||||
status=504,
|
||||
)
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'https://api-adresse.data.gouv.fr/search/',
|
||||
body=FAKED_CONTENT,
|
||||
content_type='application/json',
|
||||
status=200,
|
||||
)
|
||||
resp = app.get('/base-adresse/base-adresse/search/', params={'q': 'plop'})
|
||||
data = resp.json[0]
|
||||
assert data['lat'] == '47.474633'
|
||||
assert data['lon'] == '-0.593775'
|
||||
assert data['display_name'] == 'Rue Roger Halope 49000 Angers'
|
||||
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'https://api-adresse.data.gouv.fr/search/',
|
||||
body='Error',
|
||||
status=504,
|
||||
)
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'https://api-adresse.data.gouv.fr/search/',
|
||||
body='Error',
|
||||
status=504,
|
||||
)
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'https://api-adresse.data.gouv.fr/search/',
|
||||
body='Error',
|
||||
status=504,
|
||||
)
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'https://api-adresse.data.gouv.fr/search/',
|
||||
body='Error',
|
||||
status=504,
|
||||
)
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'https://api-adresse.data.gouv.fr/search/',
|
||||
body=FAKED_CONTENT,
|
||||
content_type='application/json',
|
||||
status=200,
|
||||
)
|
||||
resp = app.get('/base-adresse/base-adresse/search/', params={'q': 'plop'})
|
||||
assert resp.json['err'] == 1
|
||||
|
|
Loading…
Reference in New Issue