Skip to content

fix(tests): Fix flaky SessionFetchProjectReleaseHealthTotalsTest timing#108959

Merged
joshuarli merged 1 commit intomasterfrom
fix/flaky-test-release-health-totals
Feb 24, 2026
Merged

fix(tests): Fix flaky SessionFetchProjectReleaseHealthTotalsTest timing#108959
joshuarli merged 1 commit intomasterfrom
fix/flaky-test-release-health-totals

Conversation

@joshuarli
Copy link
Member

Summary

  • Fix flaky SessionFetchProjectReleaseHealthTotalsTest::test by freezing time
  • build_session() uses time.time() for session timestamps while the Snuba query uses datetime.utcnow() — these can drift between calls, especially across minute boundaries
  • Added freeze_time decorator with a deterministic timestamp and the missing super().setUp() call

Fixes #108953

Test plan

  • test passes 10/10 locally
  • test_no_data also passes

The test was flaky because build_session uses time.time() for session
timestamps while the Snuba query uses datetime.utcnow(). These can
drift between calls, especially across minute boundaries. Fix by
freezing time with a deterministic timestamp and adding the missing
super().setUp() call.

Fixes #108953
MOCK_DATETIME = (timezone.now() - timedelta(hours=1)).replace(second=30, microsecond=0)

def setUp(self) -> None:
super().setUp()
Copy link
Member

Choose a reason for hiding this comment

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

Is super.setUp() not implcit?

Copy link
Member Author

Choose a reason for hiding this comment

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

nope, if it's overridden it needs to be explicitly called

@joshuarli joshuarli merged commit 95af041 into master Feb 24, 2026
77 checks passed
@joshuarli joshuarli deleted the fix/flaky-test-release-health-totals branch February 24, 2026 01:25
mchen-sentry pushed a commit that referenced this pull request Feb 24, 2026
…ng (#108959)

## Summary
- Fix flaky `SessionFetchProjectReleaseHealthTotalsTest::test` by
freezing time
- `build_session()` uses `time.time()` for session timestamps while the
Snuba query uses `datetime.utcnow()` — these can drift between calls,
especially across minute boundaries
- Added `freeze_time` decorator with a deterministic timestamp and the
missing `super().setUp()` call

Fixes #108953

## Test plan
- [x] `test` passes 10/10 locally
- [x] `test_no_data` also passes
wedamija pushed a commit that referenced this pull request Feb 24, 2026
…ng (#108959)

## Summary
- Fix flaky `SessionFetchProjectReleaseHealthTotalsTest::test` by
freezing time
- `build_session()` uses `time.time()` for session timestamps while the
Snuba query uses `datetime.utcnow()` — these can drift between calls,
especially across minute boundaries
- Added `freeze_time` decorator with a deterministic timestamp and the
missing `super().setUp()` call

Fixes #108953

## Test plan
- [x] `test` passes 10/10 locally
- [x] `test_no_data` also passes
@github-actions github-actions bot locked and limited conversation to collaborators Mar 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: tests/sentry/release_health/release_monitor/test_metrics.py::SessionFetchProjectReleaseHealthTotalsTest::test

2 participants