Skip to content
Merged
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
15 changes: 9 additions & 6 deletions tests/sentry/runner/commands/test_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def test_no_filters(self) -> None:

assert query is not None
project_ids = list(query.values_list("id", flat=True))
assert project_ids == [project1.id, project2.id, project3.id]
# We sort the project IDs since the query set is unordered.
# Adding an order would be useless since the query from prepare_deletes_by_project is used
# by RangeQuerySetWrapper, which ignores order_by.
assert sorted(project_ids) == [project1.id, project2.id, project3.id]

def test_with_specific_project(self) -> None:
"""Test that when a specific project is provided, only that project is included."""
Expand All @@ -31,7 +34,7 @@ def test_with_specific_project(self) -> None:

assert query is not None
project_ids = list(query.values_list("id", flat=True))
assert project_ids == [project1.id]
assert sorted(project_ids) == [project1.id]

def test_with_start_from_id(self) -> None:
"""Test that when start_from_project_id is provided, projects >= that ID are included."""
Expand All @@ -47,7 +50,7 @@ def test_with_start_from_id(self) -> None:

assert query is not None
project_ids = list(query.values_list("id", flat=True))
assert project_ids == [project2.id, project3.id]
assert sorted(project_ids) == [project2.id, project3.id]

def test_specific_project_overrides_start_from(self) -> None:
"""Test that specific project_id takes precedence over start_from_project_id."""
Expand All @@ -63,7 +66,7 @@ def test_specific_project_overrides_start_from(self) -> None:
assert query is not None
project_ids = list(query.values_list("id", flat=True))
# Only project1 should be included, start_from_project_id is ignored
assert project_ids == [project1.id]
assert sorted(project_ids) == [project1.id]

def test_only_active_projects(self) -> None:
"""Test that only active projects are included."""
Expand All @@ -76,7 +79,7 @@ def test_only_active_projects(self) -> None:

assert query is not None
project_ids = list(query.values_list("id", flat=True))
assert project_ids == [active_project.id]
assert sorted(project_ids) == [active_project.id]

def test_control_silo_mode_returns_none(self) -> None:
"""Test that in CONTROL silo mode, the function returns None for query and empty list."""
Expand All @@ -98,6 +101,6 @@ def test_region_silo_mode_returns_projects(self) -> None:

assert query is not None
project_ids = list(query.values_list("id", flat=True))
assert project_ids == [project1.id, project2.id]
assert sorted(project_ids) == [project1.id, project2.id]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Test Assertions Fail Due to Unsorted Project IDs

The prepare_deletes_by_project tests sort the query results but not the expected project ID lists in the assertions. This makes the tests brittle, as they implicitly rely on project IDs being assigned in ascending order, which could lead to unexpected failures.

Fix in Cursor Fix in Web

# Should have model tuples to delete
assert len(to_delete) > 0
Loading