Skip to content

feat(dev): Prevent absolute date times#110671

Merged
armenzg merged 1 commit intomasterfrom
test_time_bombs
Mar 13, 2026
Merged

feat(dev): Prevent absolute date times#110671
armenzg merged 1 commit intomasterfrom
test_time_bombs

Conversation

@armenzg
Copy link
Member

@armenzg armenzg commented Mar 13, 2026

This is a follow-up to #110643

Unfortunately, we wasted a lot of time until we realized it was a test time bomb that caused the multi-hour deployment backlog.

This prevents same year test time bombs and fixes some potential ones.

@armenzg armenzg self-assigned this Mar 13, 2026
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 13, 2026
Copy link
Member Author

Choose a reason for hiding this comment

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

Most of the changes in these files is using before_now to freeze a datetime.

At the bottom of the PR, you will see some flake8 custom code to help catch this.



class TestEAPGetErrorsCountsTimeseries(TestCase, SnubaTestCase):
FROZEN_TIME = before_now(hours=24).replace(hour=6, minute=0, second=0)
Copy link
Member Author

Choose a reason for hiding this comment

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

The pre-commit check will notice datetime(<this_year>, ... and complain.

f"from datetime import datetime, timezone\n\n"
f"X = datetime({cy}, 1, 1, tzinfo=timezone.utc)\n",
filename="tests/x.py",
) == [f"t.py:3:0: {msg}"]
Copy link
Member Author

Choose a reason for hiding this comment

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

A non-empty list means an error was caught.

msg = _s015_msg(cy)
assert _run(
f"from datetime import datetime, timezone\n\n"
f"X = datetime({cy}, 1, 1, tzinfo=timezone.utc)\n",
Copy link
Member Author

Choose a reason for hiding this comment

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

Since it uses cy (current year) the test fill fail.

)
assert _run(
f"from freezegun import freeze_time\nfrom datetime import datetime, timezone\n\n"
f"@freeze_time(datetime({cy}, 1, 1, tzinfo=timezone.utc))\n"
Copy link
Member Author

Choose a reason for hiding this comment

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

freeze_time + current year -> failure



def _is_tests_path(filename: str) -> bool:
return "tests/" in filename or "testutils/" in filename
Copy link
Member Author

Choose a reason for hiding this comment

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

This function will be used to only check test files.

@armenzg armenzg marked this pull request as ready for review March 13, 2026 19:27
@armenzg armenzg requested a review from a team as a code owner March 13, 2026 19:27
@armenzg armenzg requested a review from a team March 13, 2026 20:29
@armenzg armenzg merged commit 227b7f6 into master Mar 13, 2026
77 checks passed
@armenzg armenzg deleted the test_time_bombs branch March 13, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants