-
Notifications
You must be signed in to change notification settings - Fork 15
Fix corrupted or incomplete files after interrupted download #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iLLiCiTiT
merged 3 commits into
bugfix/transfer-max-retries
from
bugfix/download-resume-integrity
Sep 14, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """Interrupted downloads. Does not require running AYON server.""" | ||
| import io | ||
|
|
||
| import pytest | ||
|
|
||
| from ayon_api.server_api import ServerAPI | ||
| from ayon_api.utils import RequestTypes | ||
|
|
||
| from .fake_transfer import FakeResponse | ||
|
|
||
| CONTENT = b"0123456789" | ||
| SIZE_HEADER = {"Content-Length": str(len(CONTENT))} | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def con(monkeypatch): | ||
| monkeypatch.setattr("time.sleep", lambda *args, **kwargs: None) | ||
| return ServerAPI("http://localhost:0", create_session=False, max_retries=3) | ||
|
|
||
|
|
||
| def _download(con, get_func): | ||
| con._base_functions_mapping[RequestTypes.get] = get_func | ||
| stream = io.BytesIO() | ||
| progress = con.download_file_to_stream("api/file", stream) | ||
| return stream.getvalue(), progress | ||
|
|
||
|
|
||
| def test_incomplete_download_is_continued(con): | ||
| def get_func(url, **kwargs): | ||
| if "Range" not in kwargs["headers"]: | ||
| # Connection closed after 4 bytes without an exception | ||
| return FakeResponse(200, CONTENT[:4], SIZE_HEADER) | ||
| assert kwargs["headers"]["Range"] == "bytes=4-" | ||
| return FakeResponse(206, CONTENT[4:], {"Content-Length": "6"}) | ||
|
|
||
| content, progress = _download(con, get_func) | ||
| assert content == CONTENT | ||
| assert progress.transferred_size == len(CONTENT) | ||
|
|
||
|
|
||
| def test_resume_without_range_support_does_not_duplicate(con): | ||
| calls = [] | ||
|
|
||
| def get_func(url, **kwargs): | ||
| calls.append(url) | ||
| if len(calls) == 1: | ||
| return FakeResponse(200, CONTENT[:4], SIZE_HEADER) | ||
| # Server ignores 'Range' header and sends whole file again | ||
| return FakeResponse(200, CONTENT, SIZE_HEADER) | ||
|
|
||
| content, progress = _download(con, get_func) | ||
| assert content == CONTENT | ||
| assert progress.transferred_size == len(CONTENT) | ||
|
|
||
|
|
||
| def test_download_without_content_length(con): | ||
| content, _ = _download( | ||
| con, lambda url, **kwargs: FakeResponse(200, CONTENT) | ||
| ) | ||
| assert content == CONTENT |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.