Skip to content

Commit

Permalink
fix flaky test for user notification task (#17676)
Browse files Browse the repository at this point in the history
* fix flaky test for user notification task

followup to #17662, in batch size test... just test batch size

ordering in the query won't necessarily match ordering of usernames... so just compare call counts. the other tests ensure the right users arenotified, let this one just look at the batch size

* lint

---------

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
  • Loading branch information
ewdurbin and di authored Feb 28, 2025
1 parent 59f999c commit d028de2
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions tests/unit/accounts/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_notify_users_of_tos_update_respects_batch_size(
"terms.revision": "initial",
"terms.notification_batch_size": batch_size,
}
users_to_notify = UserFactory.create_batch(20, with_verified_primary_email=True)
UserFactory.create_batch(max(1, batch_size * 2), with_verified_primary_email=True)

send_email = pretend.call_recorder(lambda request, user: None)
monkeypatch.setattr(tasks, "send_user_terms_of_service_updated", send_email)
Expand All @@ -75,19 +75,8 @@ def test_notify_users_of_tos_update_respects_batch_size(

notify_users_of_tos_update(db_request)

assert sorted(send_email.calls, key=lambda x: x.args[1]) == sorted(
[pretend.call(db_request, u) for u in users_to_notify][:batch_size],
key=lambda x: x.args[1],
)
assert sorted(
user_service.record_tos_engagement.calls, key=lambda x: x.args[0]
) == sorted(
[
pretend.call(u.id, "initial", TermsOfServiceEngagement.Notified)
for u in users_to_notify
][:batch_size],
key=lambda x: x.args[0],
)
assert len(send_email.calls) == batch_size
assert len(user_service.record_tos_engagement.calls) == batch_size


def test_notify_users_of_tos_update_does_not_renotify(
Expand Down

0 comments on commit d028de2

Please sign in to comment.