Skip to content

Commit d028de2

Browse files
ewdurbindi
andauthored
fix flaky test for user notification task (#17676)
* 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 <[email protected]>
1 parent 59f999c commit d028de2

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

tests/unit/accounts/test_tasks.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_notify_users_of_tos_update_respects_batch_size(
6464
"terms.revision": "initial",
6565
"terms.notification_batch_size": batch_size,
6666
}
67-
users_to_notify = UserFactory.create_batch(20, with_verified_primary_email=True)
67+
UserFactory.create_batch(max(1, batch_size * 2), with_verified_primary_email=True)
6868

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

7676
notify_users_of_tos_update(db_request)
7777

78-
assert sorted(send_email.calls, key=lambda x: x.args[1]) == sorted(
79-
[pretend.call(db_request, u) for u in users_to_notify][:batch_size],
80-
key=lambda x: x.args[1],
81-
)
82-
assert sorted(
83-
user_service.record_tos_engagement.calls, key=lambda x: x.args[0]
84-
) == sorted(
85-
[
86-
pretend.call(u.id, "initial", TermsOfServiceEngagement.Notified)
87-
for u in users_to_notify
88-
][:batch_size],
89-
key=lambda x: x.args[0],
90-
)
78+
assert len(send_email.calls) == batch_size
79+
assert len(user_service.record_tos_engagement.calls) == batch_size
9180

9281

9382
def test_notify_users_of_tos_update_does_not_renotify(

0 commit comments

Comments
 (0)