fix: announce each retry of a file list

This commit is contained in:
Abdessamad Derraz committed 2026-10-18 16:25:08 +02:00
1 parent eeeaa22579
commit 8247895664
4 files changed
+20 -2

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ param(
$ErrorActionPreference = "Stop"
$defaultInstallUrl = "https://raw.githubusercontent.com/Abdess/retrobios/main/install.py"
$defaultInstallSha256 = "0c3089832c2ee7e61b50a49edcd9a810814be8b5465238755b3954ff895c5e18"
$defaultInstallSha256 = "324baf5363d46da75cb7f166e83b323a40ce6502084314360f909e9d1ff4dd4e"
$maximumInstallerBytes = 2MB
$installerExit = 0
$installer = if ($PSScriptRoot) { Join-Path $PSScriptRoot "install.py" } else { $null }
+5
View File
@@ -1753,12 +1753,17 @@ def _fetch_json(url: str, limit: int, label: str) -> object:
if exc.code < 500 and exc.code != 429 or attempt == MAX_RETRIES:
raise
delay = _retry_delay(attempt, exc.headers.get("Retry-After") if exc.headers else None)
problem = f"HTTP {exc.code}"
except (urllib.error.URLError, OSError, http.client.HTTPException) as exc:
if attempt == MAX_RETRIES:
if isinstance(exc, http.client.HTTPException):
raise ConnectionError(f"connection cut: {exc!r}") from exc
raise
delay = _retry_delay(attempt, None)
problem = str(getattr(exc, "reason", None) or exc)
# Said, or three 30-second attempts read as a frozen program.
print(f" The {label} did not arrive ({problem}); trying again "
f"({attempt + 1}/{MAX_RETRIES}) in {delay:.0f} s.", file=sys.stderr)
time.sleep(delay)
raise AssertionError("unreachable")
+1 -1
View File
@@ -18,7 +18,7 @@ esac
TEMP_INSTALLER=""
TEMP_DIRECTORY=""
DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/install.py"
DEFAULT_INSTALL_SHA256="0c3089832c2ee7e61b50a49edcd9a810814be8b5465238755b3954ff895c5e18"
DEFAULT_INSTALL_SHA256="324baf5363d46da75cb7f166e83b323a40ce6502084314360f909e9d1ff4dd4e"
MAX_INSTALLER_BYTES=2097152
cleanup() {
+13
View File
@@ -2470,6 +2470,19 @@ class ACutFileListIsRetried(unittest.TestCase):
unittest.mock.patch.object(install.time, "sleep"):
self.assertEqual(install._fetch_json("https://x/y.json", 1000, "manifest"), {"a": 1})
def test_a_retry_is_announced(self):
import contextlib
full = json.dumps({"a": 1}).encode()
answers = iter([self._Response(full[:4], len(full)), self._Response(full, len(full))])
err = io.StringIO()
with unittest.mock.patch.object(install.urllib.request, "urlopen",
lambda *a, **k: next(answers)), \
unittest.mock.patch.object(install.time, "sleep"), \
contextlib.redirect_stderr(err):
install._fetch_json("https://x/y.json", 1000, "file list")
self.assertIn("trying again (2/3)", err.getvalue())
def test_a_short_body_is_a_connection_error(self):
with self.assertRaises(ConnectionError):
install._read_limited_json(self._Response(b'{"a"', 10), 1000, "manifest")