Commit fe2ef76 1 parent 81e886b commit fe2ef76 Copy full SHA for fe2ef76
File tree 2 files changed +33
-1
lines changed
cachito/workers/pkg_managers
tests/test_workers/test_pkg_managers
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -140,7 +140,9 @@ async def on_request_start(
140
140
141
141
trace_config = aiohttp .TraceConfig ()
142
142
trace_config .on_request_start .append (on_request_start )
143
- retry_options = JitterRetry (attempts = attempts , retry_all_server_errors = True )
143
+ retry_options = JitterRetry (
144
+ attempts = attempts , exceptions = {aiohttp .ClientConnectionError }, retry_all_server_errors = True
145
+ )
144
146
retry_client = RetryClient (retry_options = retry_options , trace_configs = [trace_config ])
145
147
146
148
async with retry_client as session :
Original file line number Diff line number Diff line change 10
10
from typing import Any
11
11
from unittest import mock
12
12
13
+ import aiohttp
14
+ import aiohttp_retry
13
15
import pytest
14
16
15
17
from cachito .errors import (
16
18
FileAccessError ,
17
19
InvalidFileFormat ,
18
20
InvalidRepoStructure ,
21
+ NetworkError ,
19
22
NexusError ,
20
23
RepositoryAccessError ,
21
24
UnsupportedFeature ,
@@ -261,6 +264,33 @@ def test_parse_dependency(data):
261
264
assert result == (data ["p_url" ], data ["tarball_name" ])
262
265
263
266
267
+ @pytest .mark .asyncio
268
+ async def test_async_download_binary_file_retries_on_connect_error (tmp_path : Path ):
269
+ with mock .patch (
270
+ "aiohttp.ClientSession._request" , side_effect = aiohttp .ClientConnectionError
271
+ ) as mock_request :
272
+
273
+ # Make two attempts and retry on ClientConnectionError
274
+ retry_options = aiohttp_retry .JitterRetry (
275
+ attempts = 2 ,
276
+ exceptions = {aiohttp .ClientConnectionError },
277
+ retry_all_server_errors = True ,
278
+ )
279
+ async with aiohttp_retry .RetryClient (retry_options = retry_options ) as retry_client :
280
+
281
+ # Once the attempts are exhausted, async_download_binary_file raises a NetworkError
282
+ with pytest .raises (NetworkError ):
283
+ _ = await general .async_download_binary_file (
284
+ retry_client ,
285
+ "https://example.com" ,
286
+ tmp_path ,
287
+ "foo.tgz" ,
288
+ )
289
+
290
+ # Verify that we made two attempts to download the file
291
+ assert mock_request .call_count == 2
292
+
293
+
264
294
@mock .patch ("cachito.workers.pkg_managers.general_js.async_download_binary_file" )
265
295
@pytest .mark .asyncio
266
296
async def test_get_dependecies (mock_async_download_binary_file ):
You can’t perform that action at this time.
0 commit comments