From b25f2ed5b386dae0daa8b7cc1225a9b7ac739ef1 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 1 May 2020 23:00:05 +0530 Subject: [PATCH] populate_db: Add option to specify max no of topics to create. This will help us create more topics per stream than we currently do by default. --- tools/rebuild-test-database | 1 + zilencer/management/commands/populate_db.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/rebuild-test-database b/tools/rebuild-test-database index ca0ead5578..a6e9214d6b 100755 --- a/tools/rebuild-test-database +++ b/tools/rebuild-test-database @@ -33,6 +33,7 @@ create_zulip_test # This next line can be simplified to "-n0" once we fix our app (and tests) with 0 messages. ./manage.py populate_db --test-suite -n30 --threads=1 \ + --max-topics=3 \ --huddles=0 --personals=0 --percent-huddles=0 --percent-personals=0 ./manage.py dumpdata \ diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py index b3a8df9a36..61c261747b 100644 --- a/zilencer/management/commands/populate_db.py +++ b/zilencer/management/commands/populate_db.py @@ -134,6 +134,12 @@ class Command(BaseCommand): default=0, help='The number of extra streams to create') + parser.add_argument('--max-topics', + dest='max_topics', + type=int, + default=None, + help='The number of maximum topics to create') + parser.add_argument('--huddles', dest='num_huddles', type=int, @@ -191,6 +197,11 @@ class Command(BaseCommand): if options["test_suite"]: random.seed(0) + # If max_topics is not set, we set it proportional to the + # number of messages. + if options["max_topics"] is None: + options["max_topics"] = 1 + options["num_messages"] // 100 + if options["delete"]: # Start by clearing all the data in our database clear_database() @@ -682,7 +693,7 @@ def generate_and_send_messages(data: Tuple[int, Sequence[Sequence[int]], Mapping # Pick a random subscriber to the stream message.sender = random.choice(Subscription.objects.filter( recipient=message.recipient)).user_profile - message.subject = stream.name + str(random.randint(1, 3)) + message.subject = stream.name + str(random.randint(1, options["max_topics"])) saved_data['subject'] = message.subject message.date_sent = choose_date_sent(num_messages, tot_messages, options['threads'])