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:
Tim Abbott
2016-04-12 19:49:13 -07:00
parent 81143a8c98
commit 26463bb34d
2 changed files with 6 additions and 2 deletions

View File

@@ -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 = []

View File

@@ -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) *