mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-02 04:46:18 -05:00
Fallout winds: retry a batch once when the forecast service can't be connected to (#1019)
Some checks are pending
Backend Tests / api-tests (core) (push) Waiting to run
Backend Tests / api-tests (files) (push) Waiting to run
Backend Tests / api-tests (media) (push) Waiting to run
Backend Tests / api-tests (rest) (push) Waiting to run
Backend Tests / api-contract-tests (push) Waiting to run
Backend Tests / api-migrations-and-start (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Cypress Tests / cypress-component-tests (push) Waiting to run
Cypress Tests / cypress-e2e-tests (push) Waiting to run
Dead Code / vulture (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run
Some checks are pending
Backend Tests / api-tests (core) (push) Waiting to run
Backend Tests / api-tests (files) (push) Waiting to run
Backend Tests / api-tests (media) (push) Waiting to run
Backend Tests / api-tests (rest) (push) Waiting to run
Backend Tests / api-contract-tests (push) Waiting to run
Backend Tests / api-migrations-and-start (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Cypress Tests / cypress-component-tests (push) Waiting to run
Cypress Tests / cypress-e2e-tests (push) Waiting to run
Dead Code / vulture (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run
A connection failure on any batch failed the whole daily download, discarding the batches already fetched and deferring the field to the next day. A batch which can't connect is now asked again a minute later, once, as an HTTP 429 already is. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4c9f413322
commit
f58c86af88
2 changed files with 44 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ import json
|
|||
from http import HTTPStatus
|
||||
from unittest import mock
|
||||
|
||||
import aiohttp
|
||||
import pytest
|
||||
|
||||
from modules.map import winds
|
||||
|
|
@ -238,6 +239,41 @@ async def test_fetch_wind_field_slows_down(test_directory):
|
|||
await winds.fetch_wind_field([(10, 10)])
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_fetch_wind_field_reconnects(test_directory):
|
||||
"""A request which cannot connect is asked again a minute later, once, rather than losing the
|
||||
batches already fetched."""
|
||||
unreachable = aiohttp.ClientConnectorError(mock.Mock(host='api.open-meteo.com', port=443, ssl='default'),
|
||||
OSError('Connect call failed'))
|
||||
answers = [unreachable]
|
||||
slept = []
|
||||
|
||||
async def sleep(seconds):
|
||||
slept.append(seconds)
|
||||
|
||||
service = fake_service([])
|
||||
|
||||
async def unreachable_then_fine(url):
|
||||
if answers:
|
||||
raise answers.pop()
|
||||
return await service(url)
|
||||
|
||||
with mock.patch('modules.map.winds.request_forecast', unreachable_then_fine), \
|
||||
mock.patch('modules.map.winds.asyncio.sleep', sleep):
|
||||
field = await winds.fetch_wind_field([(10, 10)])
|
||||
assert slept == [winds.BATCH_SECONDS] and field['points']
|
||||
|
||||
async def always_unreachable(url):
|
||||
raise unreachable
|
||||
|
||||
slept.clear()
|
||||
with mock.patch('modules.map.winds.request_forecast', always_unreachable), \
|
||||
mock.patch('modules.map.winds.asyncio.sleep', sleep):
|
||||
with pytest.raises(winds.WindsError, match='Could not reach the forecast service'):
|
||||
await winds.fetch_wind_field([(10, 10)])
|
||||
assert slept == [winds.BATCH_SECONDS]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_latest_winds_api(async_client, test_directory):
|
||||
request, response = await async_client.get('/api/map/fallout/winds/latest')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue