Skip to content

Commit 5001829

Browse files
authored
tests(trends): Fix flakey test due to call order (#83652)
The order the function is called is not guaranteed due to the thread pool. Assert both possibilities.
1 parent 7419924 commit 5001829

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tests/sentry/api/endpoints/test_organization_events_trends_v2.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,12 @@ def test_two_projects_same_transaction(self, mock_detect_breakpoints):
347347

348348
@mock.patch("sentry.api.endpoints.organization_events_trends_v2.detect_breakpoints")
349349
@mock.patch("sentry.api.endpoints.organization_events_trends_v2.EVENTS_PER_QUERY", 2)
350-
@pytest.mark.skip(reason="Flaking 1/17/2025")
351350
def test_two_projects_same_transaction_split_queries(self, mock_detect_breakpoints):
352351
project1 = self.create_project(organization=self.org)
353352
project2 = self.create_project(organization=self.org)
354353

355354
# force these 2 transactions from different projects
356-
# to fall into the FIRST bucket when quering
355+
# to fall into the FIRST bucket when querying
357356
for i in range(2):
358357
self.store_performance_metric(
359358
name=TransactionMRI.DURATION.value,
@@ -372,7 +371,7 @@ def test_two_projects_same_transaction_split_queries(self, mock_detect_breakpoin
372371
hours_before_now=2,
373372
)
374373
# force these 2 transactions from different projects
375-
# to fall into the SECOND bucket when quering
374+
# to fall into the SECOND bucket when querying
376375
self.store_performance_metric(
377376
name=TransactionMRI.DURATION.value,
378377
tags={"transaction": "foo bar*"},
@@ -412,10 +411,20 @@ def test_two_projects_same_transaction_split_queries(self, mock_detect_breakpoin
412411
trends_call_args_data_1 = mock_detect_breakpoints.call_args_list[0][0][0]["data"]
413412
trends_call_args_data_2 = mock_detect_breakpoints.call_args_list[1][0][0]["data"]
414413

415-
assert len(trends_call_args_data_1[f"{project1.id},foo bar*"]) > 0
416-
assert len(trends_call_args_data_1[f'{project2.id},foo bar\\\\"']) > 0
417-
assert len(trends_call_args_data_2[f'{project1.id},foo bar\\\\"']) > 0
418-
assert len(trends_call_args_data_2[f"{project2.id},foo bar*"]) > 0
414+
# the order the calls happen in is non-deterministic because of the async
415+
# nature making making the requests in a thread pool so check that 1 of
416+
# the 2 possibilities happened
417+
assert (
418+
len(trends_call_args_data_1.get(f"{project1.id},foo bar*", {})) > 0
419+
and len(trends_call_args_data_1.get(f'{project2.id},foo bar\\\\"', {})) > 0
420+
and len(trends_call_args_data_2.get(f'{project1.id},foo bar\\\\"', {})) > 0
421+
and len(trends_call_args_data_2.get(f"{project2.id},foo bar*", {})) > 0
422+
) or (
423+
len(trends_call_args_data_1.get(f'{project1.id},foo bar\\\\"', {})) > 0
424+
and len(trends_call_args_data_1.get(f"{project2.id},foo bar*", {})) > 0
425+
and len(trends_call_args_data_2.get(f"{project1.id},foo bar*", {})) > 0
426+
and len(trends_call_args_data_2.get(f'{project2.id},foo bar\\\\"', {})) > 0
427+
)
419428

420429
for trends_call_args_data in [trends_call_args_data_1, trends_call_args_data_2]:
421430
for k, v in trends_call_args_data.items():

0 commit comments

Comments
 (0)