-
Notifications
You must be signed in to change notification settings - Fork 9
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 4 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,99 @@ | ||
from types import SimpleNamespace | ||
from pathlib import Path | ||
import logging | ||
import tempfile | ||
import pytest | ||
|
||
from pygeodiff import GeoDiff | ||
from mergin.client_push import push_project_finalize, UploadJob | ||
from mergin.common import ClientError | ||
|
||
|
||
@pytest.mark.parametrize("status_code", [502, 504]) | ||
def test_push_finalize_logs_on_5xx_real_diff(caplog, status_code, tmp_path): | ||
# --- data --- | ||
data_dir = Path(__file__).resolve().parent / "test_data" | ||
base = data_dir / "base.gpkg" | ||
modified = data_dir / "inserted_1_A.gpkg" | ||
assert base.exists() | ||
assert modified.exists() | ||
|
||
diff_path = tmp_path / "base_to_inserted_1_A.diff" | ||
GeoDiff().create_changeset(str(base), str(modified), str(diff_path)) | ||
diff_size = diff_path.stat().st_size | ||
file_size = modified.stat().st_size | ||
|
||
# --- logger --- | ||
logger = logging.getLogger("mergin_test") | ||
logger.setLevel(logging.DEBUG) | ||
logger.propagate = True | ||
caplog.set_level(logging.ERROR, logger="mergin_test") | ||
|
||
# --- fake MP/MC len tam, kde treba --- | ||
varmar05 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
class MP: | ||
def __init__(self, log): | ||
self.log = log | ||
|
||
def update_metadata(self, *a, **k): | ||
pass | ||
|
||
def apply_push_changes(self, *a, **k): | ||
pass | ||
|
||
def fpath_meta(self, rel): | ||
return str(diff_path) if rel == diff_path.name else rel | ||
|
||
tx = "tx-1" | ||
|
||
class MC: | ||
varmar05 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def post(self, url, *args, **kwargs): | ||
if url.endswith(f"/v1/project/push/finish/{tx}"): | ||
err = ClientError("Gateway error") | ||
setattr(err, "http_error", status_code) | ||
raise err | ||
if url.endswith(f"/v1/project/push/cancel/{tx}"): | ||
return SimpleNamespace(msg="cancelled") | ||
return SimpleNamespace(msg="ok") | ||
|
||
tmp_dir = tempfile.TemporaryDirectory(prefix="python-api-client-test-") | ||
|
||
# --- real UploadJob objekt --- | ||
job = UploadJob( | ||
project_path="u/p", | ||
changes={ | ||
"added": [], | ||
"updated": [ | ||
{ | ||
"path": modified.name, | ||
"size": file_size, | ||
"diff": {"path": diff_path.name, "size": diff_size}, | ||
"chunks": [1], | ||
} | ||
], | ||
"removed": [], | ||
}, | ||
transaction_id=tx, | ||
mp=MP(logger), | ||
mc=MC(), | ||
tmp_dir=tmp_dir, | ||
) | ||
|
||
# nastav to, čo finalize() očakáva | ||
job.total_size = 1234 | ||
job.transferred_size = 1234 | ||
job.upload_queue_items = [1] # len pre log „Upload details“ | ||
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"} # aj tak sa 5xx vyhodí skôr | ||
|
||
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.