Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Ignore application errors in ProviderProxy #4997

Merged
merged 2 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion golem/ethereum/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import List

from web3 import Web3, HTTPProvider
from web3 import Web3

from golem.ethereum.web3.providers import ProviderProxy
from golem.report import report_calls, Component
Expand Down
6 changes: 3 additions & 3 deletions golem/ethereum/web3/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def make_request(self, method, params):
'GETH: request successful %s (%r, %r) -- result = %r',
self.provider.endpoint_uri, method, params, response
)
except (ConnectionError, ValueError,
except (ConnectionError,
socket.error, CannotHandleRequest) as exc:
retries += 1
self._register_retry()
Expand Down Expand Up @@ -91,8 +91,8 @@ def _create_remote_rpc_provider(self):
def _handle_remote_rpc_provider_failure(self, method: str, final: bool):
if final:
raise Exception(
"GETH: Node limit exhausted, request failed. method='%s'",
method
"GETH: Node limit exhausted, request failed."
f" method='{method}'",
)
logger.warning(
"GETH: '%s' request failed on '%s', "
Expand Down
23 changes: 22 additions & 1 deletion tests/golem/ethereum/web3/test_providers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=protected-access
import datetime
import time
from unittest import TestCase
Expand All @@ -11,6 +12,7 @@
SINGLE_QUERY_RETRY_LIMIT,
)


@patch('web3.providers.rpc.HTTPProvider')
class TestProviders(TestCase):
def setUp(self):
Expand Down Expand Up @@ -50,6 +52,25 @@ def test_unrecoverable_errors(self, *_):
SINGLE_QUERY_RETRY_LIMIT * len(self._nodes_list)
)

@patch(
'golem.ethereum.web3.providers.HTTPProvider.make_request',
side_effect=ValueError({
'code': -32000,
'message': 'missing trie node 32de5daba1d1013d41aca01c66772685576afb925779aa35d4d5a9de6e41d8c0 (path )', # noqa pylint: disable=line-too-long
}),
)
def test_non_connection_error(self, *_):
result = None
with self.assertRaises(ValueError):
result = self.proxy.make_request("a", [])

self.assertEqual(result, None)
self.proxy.provider.make_request.assert_called_once_with("a", [])
self.assertEqual(
self.proxy.provider.make_request.call_count,
1,
)

def test_first_retry(self, *_):
with freezegun.freeze_time(datetime.datetime.utcnow()):
now = time.time()
Expand All @@ -73,7 +94,7 @@ def test_subsequent_distant_retry(self, *_):
now = time.time()
frt = now - RETRY_COUNT_INTERVAL - 1
self.proxy._first_retry_time = frt
self._retries = 2
self.proxy._retries = 2
self.proxy._register_retry()

self.assertEqual(self.proxy._first_retry_time, now)
Expand Down