mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
fix: retry bios files by the shared rule
This commit is contained in:
1 parent
a9d94acdac
commit
c113a79c70
2 files changed
+29
-4
No files matched your search
@@ -36,7 +36,7 @@ from installer.host_fs import (
|
||||
)
|
||||
from installer.invocation import offline_requested
|
||||
from installer.local_check import _digest_file, _digest_handle, expected_hashes, unreachable_words
|
||||
from installer.network import _retry_delay, _server_delay, network_words
|
||||
from installer.network import _retry_after_failure, _server_delay, network_words
|
||||
from installer.offline import LOCAL, offline_words
|
||||
from installer.outcome import HttpReason, NetworkReason, OfflineReason, _transfer_failure
|
||||
from installer.pack_source import NOT_IN_PACK, _extract_from_pack
|
||||
@@ -185,6 +185,7 @@ def _fetch_file(job: _FileFetch) -> tuple[str, bool, str]:
|
||||
f = job.f
|
||||
reason: str = "download failed"
|
||||
refused = False
|
||||
delay: float | None
|
||||
for attempt in range(1, MAX_RETRIES + 1):
|
||||
job.begin()
|
||||
try:
|
||||
@@ -217,7 +218,10 @@ def _fetch_file(job: _FileFetch) -> tuple[str, bool, str]:
|
||||
|
||||
except urllib.error.HTTPError as exc:
|
||||
reason = _http_attempt_failure(job, exc, attempt)
|
||||
delay = _server_delay(exc, attempt)
|
||||
# A 416 refused the partial copy, dropped above: the next attempt
|
||||
# asks for the whole file.
|
||||
delay = (_server_delay(exc, attempt) if exc.code == 416 and attempt < MAX_RETRIES
|
||||
else _retry_after_failure(exc, attempt, MAX_RETRIES))
|
||||
|
||||
# http.client raises IncompleteRead (an HTTPException, not an
|
||||
# OSError) when a chunked transfer is cut, as a proxy re-encoding
|
||||
@@ -228,14 +232,14 @@ def _fetch_file(job: _FileFetch) -> tuple[str, bool, str]:
|
||||
print(f" Attempt {attempt} failed: {exc}", file=sys.stderr)
|
||||
if not refused:
|
||||
job.drop_private()
|
||||
delay = _retry_delay(attempt, None)
|
||||
delay = _retry_after_failure(exc, attempt, MAX_RETRIES)
|
||||
|
||||
finally:
|
||||
if job.partial is not None:
|
||||
job.partial.close()
|
||||
|
||||
job.take_back()
|
||||
if refused or reason == DRIVE_FULL:
|
||||
if refused or reason == DRIVE_FULL or delay is None:
|
||||
return f["dest"], False, reason
|
||||
if attempt < MAX_RETRIES and delay and _stop.wait(delay):
|
||||
return f["dest"], False, "stopped"
|
||||
|
||||
@@ -6418,6 +6418,27 @@ class ANetworkFailureNamesTheNetwork(unittest.TestCase):
|
||||
with self.subTest(error=error):
|
||||
self.assertNotIsInstance(self._fail(error), install.NetworkReason)
|
||||
|
||||
def test_a_bios_file_follows_the_shared_retry_rule(self):
|
||||
"""A 404 on a BIOS file was asked three times, the file list once."""
|
||||
cases = ((urllib.error.HTTPError("u", 404, "Not Found", None, None), 1),
|
||||
(urllib.error.HTTPError("u", 503, "Service Unavailable", None, None),
|
||||
install.MAX_RETRIES))
|
||||
for error, expected in cases:
|
||||
calls: list = []
|
||||
|
||||
def urlopen(*_args, _error=error, _calls=calls, **_kwargs):
|
||||
_calls.append(1)
|
||||
raise _error
|
||||
|
||||
entry = {"dest": "a.bin", "repo_path": "bios/a.bin", "size": 10,
|
||||
"sha256": "0" * 64}
|
||||
with self.subTest(code=error.code), \
|
||||
unittest.mock.patch.object(install.urllib.request, "urlopen", urlopen), \
|
||||
unittest.mock.patch.object(install, "_retry_delay", return_value=0):
|
||||
_dest, ok, _reason = install._download_one(entry, scratch_dir(self))
|
||||
self.assertFalse(ok)
|
||||
self.assertEqual(len(calls), expected)
|
||||
|
||||
def test_the_summary_points_at_the_connection(self):
|
||||
failures = [("a.bin", install.NetworkReason("timed out")),
|
||||
("b.bin", install.NetworkReason("Connection reset by peer"))]
|
||||
|
||||
Reference in new issue
Block a user