object_type = 'content', add_func_name = 'content_add'
objects = [Content(sha1=b'O\xb7kk\x9f\xd9Au\xa3U\x81\xffz\xe5\xe4Ml\xb8\xaa\xbb', sha1_git=b'\x86\xbck7~\x9d%\xf9\xd2gw\xa4\xa2\...x81C\xe5\xf0(<\xc7\n\x81\x98*\xe1\xe5\xb7\x1f\xaacPD\xd9;', length=4, status='visible', data=b'foo5', ctime=None), ...]
bad1 = Content(sha1=b';@\xceV\xc0_\x9d\xf6k\xc1*E\x92D~o)&\r\xf3', sha1_git=b'\xbdJ\x90,\x07\x0f\xf1)=J#\x98\xe2\xcd\x8a\xf6H...a5~gfe-\xbb\xeel\xdf\x8c\xff\x9c<\x94t{\xe9z\xb2R\xe5\x8b', length=1000, status='visible', data=b'too big', ctime=None)
bad2 = Content(sha1=b'~W\x86~n\t\x96\xbd\xdc+Y$\xa9\x13c\x054S\xf3%', sha1_git=b'b\xed\x7f\x12\x18)\xaa\xb74\x8e\x0b\xf2\\\xb...xcc\x8f\xa4!\xa8=AvP\x1f\xeb\xe7\xf1{\x82\x9b\xfd\xf8\xd5', length=1000, status='visible', data=b'to fail', ctime=None)
@patch("swh.storage.in_memory.InMemoryStorage", LimitedInMemoryStorage)
@pytest.mark.parametrize("object_type, add_func_name, objects, bad1, bad2", testdata)
def test_tenacious_proxy_storage_rate_limit(
object_type, add_func_name, objects, bad1, bad2
):
storage = get_tenacious_storage(error_rate_limit={"errors": 1, "window_size": 3})
tenacious = storage.storage
in_memory = tenacious.storage
assert isinstance(tenacious, TenaciousProxyStorage)
assert isinstance(in_memory, LimitedInMemoryStorage)
size = len(objects)
add_func = getattr(storage, add_func_name)
# with no insertion failure, no impact
> s = add_func(objects)
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_tenacious.py:378:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3/lib/python3.7/site-packages/swh/storage/proxies/validate.py:55: in content_add
return self.storage.content_add(content)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <swh.storage.proxies.tenacious.TenaciousProxyStorage object at 0x7f0021669080>
func_name = 'content_add'
objects = [Content(sha1=b'O\xb7kk\x9f\xd9Au\xa3U\x81\xffz\xe5\xe4Ml\xb8\xaa\xbb', sha1_git=b'\x86\xbck7~\x9d%\xf9\xd2gw\xa4\xa2\...x81C\xe5\xf0(<\xc7\n\x81\x98*\xe1\xe5\xb7\x1f\xaacPD\xd9;', length=4, status='visible', data=b'foo5', ctime=None), ...]
def _tenacious_add(self, func_name, objects: Iterable[BaseModel]) -> Dict[str, int]:
"""Enqueue objects to write to the storage. This checks if the queue's
threshold is hit. If it is actually write those to the storage.
"""
add_function = getattr(self.storage, func_name)
object_type = self.tenacious_methods[func_name]
# list of lists of objects; note this to_add list is consumed from the tail
to_add: List[List[BaseModel]] = [list(objects)]
n_objs: int = len(to_add[0])
results: CounterT[str] = Counter()
retries: int = self._single_object_retries
while to_add:
if self.rate_queue.limit_reached():
logging.error(
"Too many insertion errors have been detected; "
"disabling insertions"
)
raise RuntimeError(
> "Too many insertion errors have been detected; "
"disabling insertions"
)
E RuntimeError: Too many insertion errors have been detected; disabling insertions
.tox/py3/lib/python3.7/site-packages/swh/storage/proxies/tenacious.py:134: RuntimeError
TEST RESULT
TEST RESULT
- Run At
- Sep 15 2021, 3:20 PM