Skip to content

Commit

Permalink
test: Add 1-2 seconds to offsets to avoid timing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Aug 23, 2024
1 parent eda2ad0 commit e3f8001
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tests/commands/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
from tests import assert_change, assert_success

runner = CliRunner()
# Do 1-2 seconds off the minimum offset, to avoid test failures due to timing issues.
negative_offset = -2 # min 0
positive_offset = 2 # min 1


@pytest.mark.parametrize(
("seconds", "call_count"),
[
(0, 0),
(2, 1),
(app_settings.reminder_days_before_expiration * 86_400, 1),
(app_settings.reminder_days_before_expiration * 86_400 + 2, 0),
(negative_offset, 0),
(positive_offset, 1),
(app_settings.reminder_days_before_expiration * 86_400 + negative_offset, 1),
(app_settings.reminder_days_before_expiration * 86_400 + positive_offset, 0),
],
)
def test_send_reminders_intro(session, mock_send_templated_email, pending_application, seconds, call_count):
Expand Down Expand Up @@ -45,10 +48,10 @@ def test_send_reminders_intro(session, mock_send_templated_email, pending_applic
@pytest.mark.parametrize(
("seconds", "call_count"),
[
(0, 0),
(2, 1),
(app_settings.reminder_days_before_lapsed * 86_400, 1),
(app_settings.reminder_days_before_lapsed * 86_400 + 2, 0),
(negative_offset, 0),
(positive_offset, 1),
(app_settings.reminder_days_before_lapsed * 86_400 + negative_offset, 1),
(app_settings.reminder_days_before_lapsed * 86_400 + positive_offset, 0),
],
)
def test_send_reminders_submit(session, mock_send_templated_email, accepted_application, seconds, call_count):
Expand Down Expand Up @@ -78,7 +81,7 @@ def test_send_reminders_submit(session, mock_send_templated_email, accepted_appl
)


@pytest.mark.parametrize(("seconds", "lapsed"), [(0, True), (1, False)])
@pytest.mark.parametrize(("seconds", "lapsed"), [(negative_offset, True), (positive_offset, False)])
def test_set_lapsed_applications(session, pending_application, seconds, lapsed):
pending_application.created_at = (
datetime.now(pending_application.tz)
Expand Down

0 comments on commit e3f8001

Please sign in to comment.