Skip to content

Commit

Permalink
v2.13.21 - add 30s timeout to api requests
Browse files Browse the repository at this point in the history
  • Loading branch information
pritamrungta committed Nov 29, 2023
1 parent eab5571 commit e2862b6
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docs/sdk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RedBrick
Organization
----------------------
.. automodule:: redbrick.organization.RBOrganization
:members: name, org_id, create_workspace, create_project, get_project, projects_raw, projects, labeling_time, create_taxonomy, get_taxonomy, update_taxonomy
:members: name, org_id, create_workspace, create_project, get_project, taxonomies, projects_raw, projects, labeling_time, create_taxonomy, get_taxonomy, update_taxonomy
:show-inheritance:

Workspace
Expand Down
2 changes: 1 addition & 1 deletion redbrick/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from .version_check import version_check

__version__ = "2.13.20"
__version__ = "2.13.21"

# windows event loop close bug https://github.com/encode/httpx/issues/914#issuecomment-622586610
try:
Expand Down
9 changes: 8 additions & 1 deletion redbrick/common/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

from redbrick import __version__ as sdk_version # pylint: disable=cyclic-import
from redbrick.utils.logging import assert_validation, log_error, logger
from redbrick.common.constants import DEFAULT_URL, MAX_RETRY_ATTEMPTS, PEERLESS_ERRORS
from redbrick.common.constants import (
DEFAULT_URL,
MAX_RETRY_ATTEMPTS,
REQUEST_TIMEOUT,
PEERLESS_ERRORS,
)


class RBClient:
Expand Down Expand Up @@ -80,6 +85,7 @@ def execute_query(
logger.debug("Executing: " + query.strip().split("\n")[0])
response = self.session.post(
self.url,
timeout=REQUEST_TIMEOUT,
headers=self.headers,
data=self.prepare_query(query, variables),
)
Expand All @@ -104,6 +110,7 @@ async def execute_query_async(
logger.debug("Executing async: " + query.strip().split("\n")[0])
async with aio_session.post(
self.url,
timeout=REQUEST_TIMEOUT,
headers=self.headers,
data=self.prepare_query(query, variables),
) as response:
Expand Down
1 change: 1 addition & 0 deletions redbrick/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
MAX_CONCURRENCY = 30
MAX_FILE_BATCH_SIZE = 5
MAX_RETRY_ATTEMPTS = 3
REQUEST_TIMEOUT = 30

DEFAULT_URL = "https://api.redbrickai.com"

Expand Down
6 changes: 0 additions & 6 deletions tests/test_repo/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,6 @@ def get_datapoint_latest_resp(task_id): # noqa: D103
}


def get_labels_resp(mock_data: t.Optional[t.Dict]): # noqa: D103
"""Mock response for `ExportRepo.get_labels`"""
resp = {"dataPoint": {"labelData": mock_data}}
return resp


def task_search_resp(mock_stage_name): # noqa: D103
"""Mock response for `ExportRepo.task_search`"""
resp = {
Expand Down
19 changes: 1 addition & 18 deletions tests/test_repo/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
Tests for `redbrick.export.public.ExportRepo`.
These tests are to ensure data gotten from the API is properly parsed.
"""
from unittest.mock import Mock, patch, AsyncMock
from unittest.mock import Mock, patch

import aiohttp
import pytest

from tests.test_repo import fixtures
Expand Down Expand Up @@ -54,22 +53,6 @@ def test_get_datapoints_latest(mock_export_repo):
assert all(isinstance(x, str) for x in dp_ids)


@pytest.mark.unit
@pytest.mark.asyncio
async def test_get_labels(mock_export_repo):
"""Test `redbrick.repo.export.Export.get_labels`"""
mock_dp_id = "mock_dp_id"
mock_label_data = {"dpId": mock_dp_id, "random_bool": True}
mock_query = AsyncMock(return_value=fixtures.get_labels_resp(mock_label_data))
with patch.object(mock_export_repo.client, "execute_query_async", mock_query):
async with aiohttp.ClientSession() as aio_session:
resp = await mock_export_repo.get_labels(
session=aio_session, org_id="mock", project_id="mock", dp_id=mock_dp_id
)
assert isinstance(resp, dict)
assert resp == mock_label_data


@pytest.mark.unit
def test_task_search(mock_export_repo):
"""Test `redbrick.repo.export.Export.task_search`"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils/test_dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import nibabel as nib
import pytest
from nibabel.filebasedimages import ImageFileError
from rt_utils import RTStruct, RTStructBuilder # type: ignore
from rt_utils import RTStruct # type: ignore

from redbrick.utils import dicom

Expand Down

0 comments on commit e2862b6

Please sign in to comment.