-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(test): Fix flaky organization trace test sorting #97831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
asottile-sentry
merged 1 commit into
getsentry:master
from
floels:fix-flaky-uptime-trace-test
Aug 25, 2025
Merged
fix(test): Fix flaky organization trace test sorting #97831
asottile-sentry
merged 1 commit into
getsentry:master
from
floels:fix-flaky-uptime-trace-test
Aug 25, 2025
Conversation
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
3e4e0d7
to
e1fd8e0
Compare
The assert_expected_results method was using inconsistent sort keys for API results (event_id) vs expected results (guid), causing random test failures. Fix by using the same guid field from additional_attributes for both. Fixes getsentryGH-97781
e1fd8e0
to
38373e4
Compare
asottile-sentry
approved these changes
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lzhao-sentry
pushed a commit
that referenced
this pull request
Aug 25, 2025
# Goal The goal of this PR is to fix the flakiness reported in GH-97781. The unit test `test_uptime_root_tree_with_orphaned_spans` in `tests/snuba/api/endpoints/test_organization_trace.py` is randomly failing in the CI with this error: ``` AssertionError: Span 0 differs (excluding children) assert {'additional_...06400.15, ...} == {'additional_...906400.3, ...} Omitting 15 identical items, use -vv to show Differing items: {'duration': 150.0} != {'duration': 300.0} {'description': 'Uptime Check [success] - https://www.example.com/ (200)'} != {'description': 'Uptime Check [success] - https://example.com/ (301)'} ... ``` # Explanation of the flakiness The failing assertion is: https://github.com/getsentry/sentry/blob/3fa39f0740f17dab4c934b352525dbb5978e8f6e/tests/snuba/api/endpoints/test_organization_trace.py#L669-L673 `assert_expected_results` is a helper method defined in the test class which asserts that the API response matches expected results from input trace items. To do this, it sorts both the API response and the input trace item with a `(guid, request_sequence)` custom sort key: https://github.com/getsentry/sentry/blob/3fa39f0740f17dab4c934b352525dbb5978e8f6e/tests/snuba/api/endpoints/test_organization_trace.py#L465-L476 The issue is that the API response items don't have an `attributes` key but only an `additional_attributes` key. In the `sort_key` method, their `guid` will therefore default to their `event_id`, which is a randomly-generated UUID. While input trace items (`[redirect_result, final_result]`) will be ordered deterministically (based on their `request_sequence`, since they have the same `guid` of `check-123`), API response items will be ordered randomly based on their random UUID, making the assertion fail randomly (because the assertion doesn't compare related items). You can easily reproduce the failure locally by running the test 10 times in a row: ``` for i in {1..10}; do pytest tests/snuba/api/endpoints/test_organization_trace.py::OrganizationEventsTraceEndpointTest::test_with_uptime_results || exit 1; done ``` It should fail at least once. # Fix The fix is simple: rely on `additional_attributes["guid"]` to sort the API response items. Incidentally, it's exactly what is done to get the sequence number: https://github.com/getsentry/sentry/blob/3fa39f0740f17dab4c934b352525dbb5978e8f6e/tests/snuba/api/endpoints/test_organization_trace.py#L471-L475 We just need to use the same syntax. # Reproduction Run the test 10 times in a row locally (same command as above) and see that it now passes consistently. # Legal Boilerplate Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
andrewshie-sentry
pushed a commit
that referenced
this pull request
Aug 26, 2025
# Goal The goal of this PR is to fix the flakiness reported in GH-97781. The unit test `test_uptime_root_tree_with_orphaned_spans` in `tests/snuba/api/endpoints/test_organization_trace.py` is randomly failing in the CI with this error: ``` AssertionError: Span 0 differs (excluding children) assert {'additional_...06400.15, ...} == {'additional_...906400.3, ...} Omitting 15 identical items, use -vv to show Differing items: {'duration': 150.0} != {'duration': 300.0} {'description': 'Uptime Check [success] - https://www.example.com/ (200)'} != {'description': 'Uptime Check [success] - https://example.com/ (301)'} ... ``` # Explanation of the flakiness The failing assertion is: https://github.com/getsentry/sentry/blob/3fa39f0740f17dab4c934b352525dbb5978e8f6e/tests/snuba/api/endpoints/test_organization_trace.py#L669-L673 `assert_expected_results` is a helper method defined in the test class which asserts that the API response matches expected results from input trace items. To do this, it sorts both the API response and the input trace item with a `(guid, request_sequence)` custom sort key: https://github.com/getsentry/sentry/blob/3fa39f0740f17dab4c934b352525dbb5978e8f6e/tests/snuba/api/endpoints/test_organization_trace.py#L465-L476 The issue is that the API response items don't have an `attributes` key but only an `additional_attributes` key. In the `sort_key` method, their `guid` will therefore default to their `event_id`, which is a randomly-generated UUID. While input trace items (`[redirect_result, final_result]`) will be ordered deterministically (based on their `request_sequence`, since they have the same `guid` of `check-123`), API response items will be ordered randomly based on their random UUID, making the assertion fail randomly (because the assertion doesn't compare related items). You can easily reproduce the failure locally by running the test 10 times in a row: ``` for i in {1..10}; do pytest tests/snuba/api/endpoints/test_organization_trace.py::OrganizationEventsTraceEndpointTest::test_with_uptime_results || exit 1; done ``` It should fail at least once. # Fix The fix is simple: rely on `additional_attributes["guid"]` to sort the API response items. Incidentally, it's exactly what is done to get the sequence number: https://github.com/getsentry/sentry/blob/3fa39f0740f17dab4c934b352525dbb5978e8f6e/tests/snuba/api/endpoints/test_organization_trace.py#L471-L475 We just need to use the same syntax. # Reproduction Run the test 10 times in a row locally (same command as above) and see that it now passes consistently. # Legal Boilerplate Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
constantinius
pushed a commit
that referenced
this pull request
Sep 1, 2025
# Goal The goal of this PR is to fix the flakiness reported in GH-97781. The unit test `test_uptime_root_tree_with_orphaned_spans` in `tests/snuba/api/endpoints/test_organization_trace.py` is randomly failing in the CI with this error: ``` AssertionError: Span 0 differs (excluding children) assert {'additional_...06400.15, ...} == {'additional_...906400.3, ...} Omitting 15 identical items, use -vv to show Differing items: {'duration': 150.0} != {'duration': 300.0} {'description': 'Uptime Check [success] - https://www.example.com/ (200)'} != {'description': 'Uptime Check [success] - https://example.com/ (301)'} ... ``` # Explanation of the flakiness The failing assertion is: https://github.com/getsentry/sentry/blob/3fa39f0740f17dab4c934b352525dbb5978e8f6e/tests/snuba/api/endpoints/test_organization_trace.py#L669-L673 `assert_expected_results` is a helper method defined in the test class which asserts that the API response matches expected results from input trace items. To do this, it sorts both the API response and the input trace item with a `(guid, request_sequence)` custom sort key: https://github.com/getsentry/sentry/blob/3fa39f0740f17dab4c934b352525dbb5978e8f6e/tests/snuba/api/endpoints/test_organization_trace.py#L465-L476 The issue is that the API response items don't have an `attributes` key but only an `additional_attributes` key. In the `sort_key` method, their `guid` will therefore default to their `event_id`, which is a randomly-generated UUID. While input trace items (`[redirect_result, final_result]`) will be ordered deterministically (based on their `request_sequence`, since they have the same `guid` of `check-123`), API response items will be ordered randomly based on their random UUID, making the assertion fail randomly (because the assertion doesn't compare related items). You can easily reproduce the failure locally by running the test 10 times in a row: ``` for i in {1..10}; do pytest tests/snuba/api/endpoints/test_organization_trace.py::OrganizationEventsTraceEndpointTest::test_with_uptime_results || exit 1; done ``` It should fail at least once. # Fix The fix is simple: rely on `additional_attributes["guid"]` to sort the API response items. Incidentally, it's exactly what is done to get the sequence number: https://github.com/getsentry/sentry/blob/3fa39f0740f17dab4c934b352525dbb5978e8f6e/tests/snuba/api/endpoints/test_organization_trace.py#L471-L475 We just need to use the same syntax. # Reproduction Run the test 10 times in a row locally (same command as above) and see that it now passes consistently. # Legal Boilerplate Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Goal
The goal of this PR is to fix the flakiness reported in GH-97781. The unit test
test_uptime_root_tree_with_orphaned_spans
intests/snuba/api/endpoints/test_organization_trace.py
is randomly failing in the CI with this error:Explanation of the flakiness
The failing assertion is:
sentry/tests/snuba/api/endpoints/test_organization_trace.py
Lines 669 to 673 in 3fa39f0
assert_expected_results
is a helper method defined in the test class which asserts that the API response matches expected results from input trace items. To do this, it sorts both the API response and the input trace item with a(guid, request_sequence)
custom sort key:sentry/tests/snuba/api/endpoints/test_organization_trace.py
Lines 465 to 476 in 3fa39f0
The issue is that the API response items don't have an
attributes
key but only anadditional_attributes
key. In thesort_key
method, theirguid
will therefore default to theirevent_id
, which is a randomly-generated UUID. While input trace items ([redirect_result, final_result]
) will be ordered deterministically (based on theirrequest_sequence
, since they have the sameguid
ofcheck-123
), API response items will be ordered randomly based on their random UUID, making the assertion fail randomly (because the assertion doesn't compare related items).You can easily reproduce the failure locally by running the test 10 times in a row:
It should fail at least once.
Fix
The fix is simple: rely on
additional_attributes["guid"]
to sort the API response items. Incidentally, it's exactly what is done to get the sequence number:sentry/tests/snuba/api/endpoints/test_organization_trace.py
Lines 471 to 475 in 3fa39f0
We just need to use the same syntax.
Reproduction
Run the test 10 times in a row locally (same command as above) and see that it now passes consistently.
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.