test: assert expired snapshot ids in expire_snapshots tests#3615
Open
anxkhn wants to merge 1 commit into
Open
Conversation
test_expire_unprotected_snapshot and test_expire_snapshots_by_ids mocked the catalog and hardcoded the commit_table response metadata to snapshots=[KEEP_SNAPSHOT]. After commit, Table._do_commit sets self.metadata = response.metadata, so the post-conditions only re-checked that canned value: "EXPIRE_SNAPSHOT not in [KEEP_SNAPSHOT]" is int-not-in-list (always true for distinct ids) and len(snapshots) == 1 just reads the mock. Both tests still passed with ExpireSnapshots.by_id/by_ids neutered to no-ops, so they did not exercise the expiration logic. Assert the RemoveSnapshotsUpdate.snapshot_ids actually passed to commit_table instead, matching the existing pattern in test_expire_snapshots_by_timestamp_skips_protected. Compare as a set because the update's ids come from a set. With this change both tests fail when the wrong ids (or none) are expired. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Rationale for this change
test_expire_unprotected_snapshotandtest_expire_snapshots_by_idsintests/table/test_expire_snapshots.pydo not actually exercise the expirationlogic. Both tests mock the catalog and hardcode the
commit_tableresponsemetadata to
snapshots=[KEEP_SNAPSHOT]. After the commit,Table._do_commitsets
self.metadata = response.metadata, sotable_v2.metadata.snapshotsbecomes that canned value regardless of which ids
ExpireSnapshotsactuallyselected. The post-conditions then only re-read the mock:
assert EXPIRE_SNAPSHOT not in remaining_snapshotscompares an int against alist of a different int, which is always true.
assert len(table_v2.metadata.snapshots) == 1just reads the hardcodedsingle-element list.
As a result, both tests still pass even when
ExpireSnapshots.by_id/by_idsare neutered to no-ops (nothing is expired), so a regression that selected the
wrong snapshot ids, or none, would not be caught.
This mirrors the assertion style already used correctly in the same file by
test_expire_snapshots_by_timestamp_skips_protected, which inspects theRemoveSnapshotsUpdatesent tocommit_tableinstead of the mocked response.Are these changes tested?
Yes; this change is entirely to tests. It replaces the assertions in the two
tests above with an inspection of the
RemoveSnapshotsUpdate.snapshot_idsactually passed to
commit_table(viacall_args), comparing as a set becausethe update's ids are built from a
set.python -m pytest tests/table/test_expire_snapshots.py-> 9 passed.ExpireSnapshots.by_id/by_idstemporarily stubbed to no-ops, both tests now fail (the capturedsnapshot_idsset is empty), whereas before this change they still passed.Are there any user-facing changes?
No. Test-only change; no library code is modified.
Notes for maintainers (optional comment, not part of the template)
real expiration result. The other tests in the file are unchanged.
call_argsinspection is duplicated across three tests now(including the pre-existing
..._skips_protected). I kept it inline to matchthe established in-file pattern rather than introduce a helper in this PR; happy
to factor it out if preferred.