-
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 1 commit
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,108 @@ | ||
import logging | ||
import tempfile | ||
from pathlib import Path | ||
from types import SimpleNamespace | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize("status_code", [502, 504]) | ||
def test_push_finalize_logs_on_5xx_real_diff(caplog, status_code): | ||
# geodiff is required – if missing, skip the test gracefully | ||
varmar05 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
pytest.importorskip("pygeodiff") | ||
from pygeodiff import GeoDiff | ||
|
||
from mergin.client_push import push_project_finalize | ||
from mergin.common import ClientError | ||
|
||
# --- exact paths according to your repo structure --- | ||
data_dir = Path(__file__).resolve().parent / "test_data" | ||
base = data_dir / "base.gpkg" | ||
modified = data_dir / "inserted_1_A.gpkg" | ||
|
||
# if something is missing, print the directory contents and FAIL | ||
varmar05 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if not base.exists() or not modified.exists(): | ||
print("[DEBUG] data_dir:", data_dir) | ||
print("[DEBUG] data_dir.exists():", data_dir.exists()) | ||
if data_dir.exists(): | ||
print("[DEBUG] contents:", [p.name for p in sorted(data_dir.iterdir())]) | ||
pytest.fail(f"Expected files are not available: base={base.exists()} inserted_1_A={modified.exists()}") | ||
|
||
# --- create a real .diff (changeset) --- | ||
with tempfile.TemporaryDirectory(prefix="geodiff-") as tmpdir: | ||
tmpdir = Path(tmpdir) | ||
diff_path = tmpdir / "base_to_inserted_1_A.diff" | ||
|
||
gd = GeoDiff() | ||
gd.create_changeset(str(base), str(modified), str(diff_path)) | ||
diff_size = diff_path.stat().st_size | ||
file_size = modified.stat().st_size | ||
|
||
# --- logger captured by caplog --- | ||
logger = logging.getLogger("mergin_test") | ||
logger.setLevel(logging.DEBUG) | ||
logger.propagate = True | ||
|
||
# --- fake mc.post: /finish -> 5xx, /cancel -> ok --- | ||
def fake_post(url, *args, **kwargs): | ||
if "/finish/" in url: | ||
err = ClientError("Gateway error") | ||
setattr(err, "http_error", status_code) | ||
raise err | ||
if "/cancel/" in url: | ||
return SimpleNamespace(msg="cancelled") | ||
return SimpleNamespace(msg="ok") | ||
|
||
# --- fake future/executor (no exceptions) --- | ||
fake_future = SimpleNamespace(done=lambda: True, exception=lambda: None, running=lambda: False) | ||
fake_executor = SimpleNamespace(shutdown=lambda wait=True: None) | ||
|
||
# mp.fpath_meta should resolve the relative diff path to an absolute path | ||
def fpath_meta(rel): | ||
return str(diff_path) if rel == diff_path.name else rel | ||
|
||
# --- minimal job – only what finalize() uses --- | ||
job = SimpleNamespace( | ||
varmar05 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
executor=fake_executor, | ||
futures=[fake_future], | ||
transferred_size=1234, | ||
total_size=1234, | ||
upload_queue_items=[1], | ||
transaction_id="tx-1", | ||
mp=SimpleNamespace( | ||
log=logger, | ||
update_metadata=lambda *a, **k: None, | ||
apply_push_changes=lambda *a, **k: None, | ||
fpath_meta=fpath_meta, | ||
), | ||
mc=SimpleNamespace(post=fake_post), | ||
changes={ | ||
"added": [], | ||
"updated": [{ | ||
"path": modified.name, | ||
"size": file_size, | ||
"diff": {"path": diff_path.name, "size": diff_size}, | ||
"chunks": [1], | ||
}], | ||
"removed": [], | ||
}, | ||
tmp_dir=SimpleNamespace(cleanup=lambda: None), | ||
) | ||
|
||
# capture ERROR-level logs from "mergin_test" | ||
caplog.set_level(logging.ERROR, logger="mergin_test") | ||
|
||
# --- call production logic (expecting 5xx) --- | ||
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 | ||
# helper may compute changes, or log changes=n/a – accept both | ||
assert ("changes=" in text) or ("changes=n/a" in text) |
Oops, something went wrong.
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.