Skip to content

Commit 61087e4

Browse files
authored
Make rest client time out after 10s (#20)
1 parent 48fdb78 commit 61087e4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

go2rtc_client/rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
from typing import TYPE_CHECKING, Any, Final, Literal
77

8-
from aiohttp import ClientError, ClientResponse, ClientSession
8+
from aiohttp import ClientError, ClientResponse, ClientSession, ClientTimeout
99
from aiohttp.client import _RequestOptions
1010
from awesomeversion import AwesomeVersion, AwesomeVersionException
1111
from mashumaro.codecs.basic import BasicDecoder
@@ -46,7 +46,7 @@ async def request(
4646
_LOGGER.debug("request[%s] %s", method, url)
4747
if isinstance(data, DataClassDictMixin):
4848
data = data.to_dict()
49-
kwargs = _RequestOptions({})
49+
kwargs = _RequestOptions(timeout=ClientTimeout(total=10))
5050
if params:
5151
kwargs["params"] = params
5252
if data:

tests/test_rest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
from typing import TYPE_CHECKING, Any
88

9+
from aiohttp import ClientTimeout
910
from aiohttp.hdrs import METH_PUT
1011
from awesomeversion import AwesomeVersion
1112
import pytest
@@ -93,7 +94,9 @@ async def test_streams_add(
9394
"camera.12mp_fluent", "rtsp://test:test@192.168.10.105:554/Preview_06_sub"
9495
)
9596

96-
responses.assert_called_once_with(url, method=METH_PUT, params=params)
97+
responses.assert_called_once_with(
98+
url, method=METH_PUT, params=params, timeout=ClientTimeout(total=10)
99+
)
97100

98101

99102
VERSION_ERR = "server version '{}' not >= 1.9.5 and < 2.0.0"

0 commit comments

Comments
 (0)