Skip to content

Commit

Permalink
Make rest client time out after 10s (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Oct 30, 2024
1 parent 48fdb78 commit 61087e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions go2rtc_client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,7 +94,9 @@ async def test_streams_add(
"camera.12mp_fluent", "rtsp://test:[email protected]: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"
Expand Down

0 comments on commit 61087e4

Please sign in to comment.