Retry rate-limited HLS segments
This commit is contained in:
+28
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user