-
Notifications
You must be signed in to change notification settings - Fork 11
extend 502/504 failure logging #268
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
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1d26f6a
feat(push): extend 502/504 failure logging with upload summary and fi…
DanChov 8317269
black -l 120
DanChov ed7e276
eddited after rewiew:
DanChov 70d3eda
black -l 120
DanChov 8019b01
changes based on review: try-except should catch more geodiff errors …
DanChov e65bf01
added FileNotFoundError
DanChov f078c85
black
DanChov 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| from types import SimpleNamespace | ||
| from pathlib import Path | ||
| import logging | ||
| import tempfile | ||
| from unittest.mock import MagicMock | ||
| import pytest | ||
|
|
||
| from pygeodiff import GeoDiff | ||
| from mergin.client_push import push_project_finalize, UploadJob | ||
| from mergin.common import ClientError | ||
| from mergin.merginproject import MerginProject | ||
| from mergin.client import MerginClient | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("status_code", [502, 504]) | ||
| def test_push_finalize_logs_on_5xx_real_diff(caplog, status_code, tmp_path): | ||
| # test data | ||
| data_dir = Path(__file__).resolve().parent / "test_data" | ||
| base = data_dir / "base.gpkg" | ||
| modified = data_dir / "inserted_1_A.gpkg" | ||
| assert base.exists() and modified.exists() | ||
|
|
||
| # real MerginProject in temp dir | ||
| proj_dir = tmp_path / "proj" | ||
| meta_dir = proj_dir / ".mergin" | ||
| meta_dir.mkdir(parents=True) | ||
| mp = MerginProject(str(proj_dir)) | ||
|
|
||
| # route MP logs into pytest caplog | ||
| logger = logging.getLogger("mergin_test") | ||
| logger.setLevel(logging.DEBUG) | ||
| logger.propagate = True | ||
| caplog.set_level(logging.ERROR, logger="mergin_test") | ||
| mp.log = logger | ||
|
|
||
| # generate a real diff into .mergin/ | ||
| diff_path = meta_dir / "base_to_inserted_1_A.diff" | ||
| GeoDiff().create_changeset(str(base), str(modified), str(diff_path)) | ||
| diff_rel = diff_path.name | ||
| diff_size = diff_path.stat().st_size | ||
| file_size = modified.stat().st_size | ||
|
|
||
| # mock MerginClient: only patch post(); simulate 5xx on finish | ||
| tx = "tx-1" | ||
|
|
||
| def mc_post(url, *args, **kwargs): | ||
| if url.endswith(f"/v1/project/push/finish/{tx}"): | ||
| err = ClientError("Gateway error") | ||
| setattr(err, "http_error", status_code) # emulate HTTP code on the exception | ||
| raise err | ||
| if url.endswith(f"/v1/project/push/cancel/{tx}"): | ||
| return SimpleNamespace(msg="cancelled") | ||
| return SimpleNamespace(msg="ok") | ||
|
|
||
| mc = MagicMock(spec=MerginClient) | ||
| mc.post.side_effect = mc_post | ||
|
|
||
| tmp_dir = tempfile.TemporaryDirectory(prefix="python-api-client-test-") | ||
|
|
||
| # build a real UploadJob that references the diff/file sizes | ||
| job = UploadJob( | ||
| project_path="u/p", | ||
| changes={ | ||
| "added": [], | ||
| "updated": [ | ||
| { | ||
| "path": modified.name, | ||
| "size": file_size, | ||
| "diff": {"path": diff_rel, "size": diff_size}, | ||
| "chunks": [1], | ||
| } | ||
| ], | ||
| "removed": [], | ||
| }, | ||
| transaction_id=tx, | ||
| mp=mp, | ||
| mc=mc, | ||
| tmp_dir=tmp_dir, | ||
| ) | ||
|
|
||
| job.total_size = 1234 | ||
| job.transferred_size = 1234 | ||
| job.upload_queue_items = [1] | ||
| job.executor = SimpleNamespace(shutdown=lambda wait=True: None) | ||
| job.futures = [SimpleNamespace(done=lambda: True, exception=lambda: None, running=lambda: False)] | ||
| job.server_resp = {"version": "n/a"} | ||
|
|
||
| with pytest.raises(ClientError): | ||
| push_project_finalize(job) | ||
|
|
||
| text = caplog.text | ||
| assert f"Push failed with HTTP error {status_code}" in text | ||
| assert "Upload details:" in text | ||
| assert "Files:" in text | ||
| assert modified.name in text | ||
| assert f"size={file_size}" in text | ||
| assert f"diff_size={diff_size}" in text | ||
| assert ("changes=" in text) or ("changes=n/a" in text) |
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
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.