Skip to content

Commit 0cbfc4c

Browse files
authored
fix(cleanup): Fix flaky test (#102077)
Calls to `prepare_deletes_by_project` are not ordered, thus, adjusting the tests. Fixes [SENTRY-TESTS-19TC](https://sentry.sentry.io/issues/6971597318/).
1 parent 02d0649 commit 0cbfc4c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

tests/sentry/runner/commands/test_cleanup.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ def test_no_filters(self) -> None:
1818

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

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

3235
assert query is not None
3336
project_ids = list(query.values_list("id", flat=True))
34-
assert project_ids == [project1.id]
37+
assert sorted(project_ids) == [project1.id]
3538

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

4851
assert query is not None
4952
project_ids = list(query.values_list("id", flat=True))
50-
assert project_ids == [project2.id, project3.id]
53+
assert sorted(project_ids) == [project2.id, project3.id]
5154

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

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

7780
assert query is not None
7881
project_ids = list(query.values_list("id", flat=True))
79-
assert project_ids == [active_project.id]
82+
assert sorted(project_ids) == [active_project.id]
8083

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

99102
assert query is not None
100103
project_ids = list(query.values_list("id", flat=True))
101-
assert project_ids == [project1.id, project2.id]
104+
assert sorted(project_ids) == [project1.id, project2.id]
102105
# Should have model tuples to delete
103106
assert len(to_delete) > 0

0 commit comments

Comments
 (0)