From 61087e4cdc5c0892058e6d89f52320454dbc7d6b Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 30 Oct 2024 12:44:52 +0100 Subject: [PATCH] Make rest client time out after 10s (#20) --- go2rtc_client/rest.py | 4 ++-- tests/test_rest.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/go2rtc_client/rest.py b/go2rtc_client/rest.py index 0630272..db6f36e 100644 --- a/go2rtc_client/rest.py +++ b/go2rtc_client/rest.py @@ -5,7 +5,7 @@ import logging from typing import TYPE_CHECKING, Any, Final, Literal -from aiohttp import ClientError, ClientResponse, ClientSession +from aiohttp import ClientError, ClientResponse, ClientSession, ClientTimeout from aiohttp.client import _RequestOptions from awesomeversion import AwesomeVersion, AwesomeVersionException from mashumaro.codecs.basic import BasicDecoder @@ -46,7 +46,7 @@ async def request( _LOGGER.debug("request[%s] %s", method, url) if isinstance(data, DataClassDictMixin): data = data.to_dict() - kwargs = _RequestOptions({}) + kwargs = _RequestOptions(timeout=ClientTimeout(total=10)) if params: kwargs["params"] = params if data: diff --git a/tests/test_rest.py b/tests/test_rest.py index 53b918c..654a79b 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -6,6 +6,7 @@ import json from typing import TYPE_CHECKING, Any +from aiohttp import ClientTimeout from aiohttp.hdrs import METH_PUT from awesomeversion import AwesomeVersion import pytest @@ -93,7 +94,9 @@ async def test_streams_add( "camera.12mp_fluent", "rtsp://test:test@192.168.10.105:554/Preview_06_sub" ) - responses.assert_called_once_with(url, method=METH_PUT, params=params) + responses.assert_called_once_with( + url, method=METH_PUT, params=params, timeout=ClientTimeout(total=10) + ) VERSION_ERR = "server version '{}' not >= 1.9.5 and < 2.0.0"