Skip to content

Commit

Permalink
fix tests and linters
Browse files Browse the repository at this point in the history
  • Loading branch information
F4ever committed Apr 1, 2023
1 parent 1ecff3a commit cb6d454
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/modules/submodules/oracle_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from dataclasses import asdict
from enum import Enum

from requests.exceptions import ConnectionError
from timeout_decorator import timeout, TimeoutError
from requests.exceptions import ConnectionError as RequestsConnectionError
from timeout_decorator import timeout, TimeoutError as DecoratorTimeoutError

from src.metrics.prometheus.basic import ORACLE_BLOCK_NUMBER, ORACLE_SLOT_NUMBER
from src.modules.submodules.exceptions import IsNotMemberException, IncompatibleContractVersion
Expand Down Expand Up @@ -88,11 +88,11 @@ def run_cycle(self, blockstamp: BlockStamp) -> ModuleExecuteDelay:
except IncompatibleContractVersion as exception:
logger.error({'msg': 'Incompatible Contract version. Please update Oracle Daemon.'})
raise exception
except TimeoutError as exception:
except DecoratorTimeoutError as exception:
logger.error({'msg': 'Oracle module do not respond.', 'error': str(exception)})
except NoActiveProviderError as exception:
logger.error({'msg': 'No active node available.', 'error': str(exception)})
except ConnectionError as error:
except RequestsConnectionError as error:
logger.error({'msg': 'Connection error.', 'error': str(error)})
except NotOkResponse as error:
logger.error({'msg': 'Received non-ok response.', 'error': str(error)})
Expand Down
16 changes: 8 additions & 8 deletions src/providers/http_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from prometheus_client import Histogram
from requests import Session, JSONDecodeError
from requests.adapters import HTTPAdapter
from requests.exceptions import ConnectionError
from requests.exceptions import ConnectionError as RequestsConnectionError
from urllib3 import Retry

from src.variables import HTTP_REQUEST_RETRY_COUNT, HTTP_REQUEST_SLEEP_BEFORE_RETRY_IN_SECONDS, HTTP_REQUEST_TIMEOUT
Expand Down Expand Up @@ -115,20 +115,20 @@ def _get_without_fallbacks(
params=query_params,
timeout=HTTP_REQUEST_TIMEOUT,
)
except ConnectionError as error:
except RequestsConnectionError as error:
logger.debug({'msg': str(error)})
t.labels(
endpoint=endpoint,
code=0,
domain=urlparse(host).netloc,
)
raise error
else:
t.labels(
endpoint=endpoint,
code=response.status_code,
domain=urlparse(host).netloc,
)

t.labels(
endpoint=endpoint,
code=response.status_code,
domain=urlparse(host).netloc,
)

response_fail_msg = f'Response from {complete_endpoint} [{response.status_code}] with text: "{str(response.text)}" returned.'

Expand Down
7 changes: 5 additions & 2 deletions tests/modules/submodules/test_oracle_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from typing import Type

import pytest
from requests.exceptions import ConnectionError as RequestsConnectionError
from timeout_decorator import TimeoutError as DecoratorTimeoutError

from web3_multi_provider.multi_http_provider import NoActiveProviderError

from src.modules.submodules.exceptions import IsNotMemberException, IncompatibleContractVersion
Expand Down Expand Up @@ -92,9 +95,9 @@ def _throw_on_third_call():
@pytest.mark.parametrize(
"ex",
[
TimeoutError,
DecoratorTimeoutError,
NoActiveProviderError,
ConnectionError,
RequestsConnectionError,
NotOkResponse,
NoSlotsAvailable,
SlotNotFinalized,
Expand Down

0 comments on commit cb6d454

Please sign in to comment.