mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 10:57:58 +00:00
Fix nondeterministic subscriptions for default test users.
Previously, the UserProfile objects were created in the order generated by a Set, which meant tests would randomly start failing if the code that runs before this part of populate_db changed (and thus caused the Set object used to pass users into bulk_create_users to have a different order when enumerated). This fixes the issue in two ways -- one by sorting the users inside bulk_create_users, and second by attaching subscriptions to users based on a deterministic ordering.
This commit is contained in:
@@ -27,6 +27,7 @@ def bulk_create_users(realms, users_raw, bot=False):
|
||||
continue
|
||||
users.append((email, full_name, short_name, active))
|
||||
existing_users.add(email)
|
||||
users = sorted(users)
|
||||
|
||||
# Now create user_profiles
|
||||
profiles_to_create = []
|
||||
|
||||
@@ -139,9 +139,12 @@ class Command(BaseCommand):
|
||||
create_streams(realms, zulip_realm, stream_list)
|
||||
recipient_streams = [Stream.objects.get(name=name, realm=zulip_realm).id for name in stream_list]
|
||||
|
||||
# Create subscriptions to streams
|
||||
# Create subscriptions to streams. The following
|
||||
# algorithm will give each of the users a different but
|
||||
# deterministic subset of the streams (given a fixed list
|
||||
# of users).
|
||||
subscriptions_to_add = []
|
||||
profiles = UserProfile.objects.select_related().all()
|
||||
profiles = UserProfile.objects.select_related().all().order_by("email")
|
||||
for i, profile in enumerate(profiles):
|
||||
# Subscribe to some streams.
|
||||
for type_id in recipient_streams[:int(len(recipient_streams) *
|
||||
|
||||
Reference in New Issue
Block a user