Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jqueue/adapters/storage/gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,5 @@ def _sync_write(self, content: bytes, if_match: str | None) -> str:
except gapi_exc.PreconditionFailed as exc:
raise CASConflictError("GCS generation mismatch") from exc

blob.reload()
# upload_from_string() already set blob.generation from the response.
return str(blob.generation)
29 changes: 27 additions & 2 deletions tests/test_storage_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,37 @@ def test_sync_write_returns_generation_as_string():
assert etag == "77"


def test_sync_write_reloads_blob_after_upload():
def test_sync_write_does_not_reload_blob_after_upload():
pytest.importorskip("google.api_core.exceptions")
storage, blob, _ = _make_storage()
blob.generation = 55
storage._sync_write(b"content", if_match=None)
blob.reload.assert_called_once()
blob.reload.assert_not_called()


def test_sync_write_returns_uploaded_generation_not_a_later_one():
pytest.importorskip("google.api_core.exceptions")
storage, blob, _ = _make_storage()

def upload(*args: object, **kwargs: object) -> None:
blob.generation = 5 # set from our upload response

def reload(*args: object, **kwargs: object) -> None:
blob.generation = 6 # someone else wrote after us

blob.upload_from_string.side_effect = upload
blob.reload.side_effect = reload

assert storage._sync_write(b"content", if_match="4") == "5"


def test_sync_write_precondition_failed_does_not_reload():
gapi_exc = pytest.importorskip("google.api_core.exceptions")
storage, blob, _ = _make_storage()
blob.upload_from_string.side_effect = gapi_exc.PreconditionFailed("mismatch")
with pytest.raises(CASConflictError):
storage._sync_write(b"content", if_match="42")
blob.reload.assert_not_called()


def test_sync_write_precondition_failed_raises_cas_conflict():
Expand Down
Loading