Increase backup upload timeout (#132990)

This commit is contained in:
Joakim Sørensen 2024-12-16 19:12:15 +01:00 committed by GitHub
parent 77fb440ed4
commit 482ad6fbee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -7,7 +7,7 @@ from collections.abc import AsyncIterator, Callable, Coroutine
import hashlib import hashlib
from typing import Any, Self from typing import Any, Self
from aiohttp import ClientError, StreamReader from aiohttp import ClientError, ClientTimeout, StreamReader
from hass_nabucasa import Cloud, CloudError from hass_nabucasa import Cloud, CloudError
from hass_nabucasa.cloud_api import ( from hass_nabucasa.cloud_api import (
async_files_delete_file, async_files_delete_file,
@ -151,9 +151,10 @@ class CloudBackupAgent(BackupAgent):
details["url"], details["url"],
data=await open_stream(), data=await open_stream(),
headers=details["headers"] | {"content-length": str(backup.size)}, headers=details["headers"] | {"content-length": str(backup.size)},
timeout=ClientTimeout(connect=10.0, total=43200.0), # 43200s == 12h
) )
upload_status.raise_for_status() upload_status.raise_for_status()
except ClientError as err: except (TimeoutError, ClientError) as err:
raise BackupAgentError("Failed to upload backup") from err raise BackupAgentError("Failed to upload backup") from err
async def async_delete_backup( async def async_delete_backup(

View File

@ -372,6 +372,7 @@ async def test_agents_upload(
assert f"Uploading backup {backup_id}" in caplog.text assert f"Uploading backup {backup_id}" in caplog.text
@pytest.mark.parametrize("put_mock_kwargs", [{"status": 500}, {"exc": TimeoutError}])
@pytest.mark.usefixtures("cloud_logged_in", "mock_list_files") @pytest.mark.usefixtures("cloud_logged_in", "mock_list_files")
async def test_agents_upload_fail_put( async def test_agents_upload_fail_put(
hass: HomeAssistant, hass: HomeAssistant,
@ -379,6 +380,7 @@ async def test_agents_upload_fail_put(
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker, aioclient_mock: AiohttpClientMocker,
mock_get_upload_details: Mock, mock_get_upload_details: Mock,
put_mock_kwargs: dict[str, Any],
) -> None: ) -> None:
"""Test agent upload backup fails.""" """Test agent upload backup fails."""
client = await hass_client() client = await hass_client()
@ -395,7 +397,7 @@ async def test_agents_upload_fail_put(
protected=True, protected=True,
size=0.0, size=0.0,
) )
aioclient_mock.put(mock_get_upload_details.return_value["url"], status=500) aioclient_mock.put(mock_get_upload_details.return_value["url"], **put_mock_kwargs)
with ( with (
patch( patch(