Retry rate-limited HLS segments

This commit is contained in:
Dymas
2026-08-14 12:53:13 +02:00
parent be0e4948a4
commit 376301f39f
5 changed files with 106 additions and 4 deletions
+28
View File
@@ -8,6 +8,7 @@ import sys
import tempfile
import threading
import unittest
import urllib.error
from http import HTTPStatus
from pathlib import Path
from unittest import mock
@@ -4356,6 +4357,33 @@ seg-3.ts
)
)
def test_fetch_bytes_with_retries_recovers_from_segment_rate_limit(self):
error = urllib.error.HTTPError(
"https://cdn.example/video/raw-segment",
429,
"Too Many Requests",
hdrs={},
fp=None,
)
try:
with mock.patch.object(
provider_downloader,
"fetch_bytes",
side_effect=[error, b"video"],
) as fetch_bytes, mock.patch.object(provider_downloader.time, "sleep") as sleep:
data = provider_downloader.fetch_bytes_with_retries(
"https://cdn.example/video/raw-segment",
retries=1,
retry_label="segment",
)
finally:
error.close()
self.assertEqual(data, b"video")
self.assertEqual(fetch_bytes.call_count, 2)
sleep.assert_called_once()
class DockerfilePackagingTests(unittest.TestCase):
def test_provider_updates_module_is_copied_into_image(self):