2020-06-11 00:54:34 +02:00
|
|
|
from django.utils.timezone import timedelta as timezone_timedelta
|
|
|
|
|
2019-07-11 02:14:40 +02:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
2020-06-11 00:54:34 +02:00
|
|
|
from zilencer.management.commands.populate_db import choose_date_sent
|
2019-07-11 02:14:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestChoosePubDate(ZulipTestCase):
|
2019-08-28 02:43:19 +02:00
|
|
|
def test_choose_date_sent_large_tot_messages(self) -> None:
|
2019-07-11 02:14:40 +02:00
|
|
|
"""
|
|
|
|
Test for a bug that was present, where specifying a large amount of messages to generate
|
2019-08-28 02:43:19 +02:00
|
|
|
would cause each message to have date_sent set to timezone_now(), instead of the date_sents
|
2019-07-11 02:14:40 +02:00
|
|
|
being distributed across the span of several days.
|
|
|
|
"""
|
|
|
|
tot_messages = 1000000
|
|
|
|
datetimes_list = [
|
2019-08-28 02:43:19 +02:00
|
|
|
choose_date_sent(i, tot_messages, 1) for i in range(1, tot_messages, tot_messages // 100)
|
2019-07-11 02:14:40 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
# Verify there is a meaningful difference between elements.
|
|
|
|
for i in range(1, len(datetimes_list)):
|
|
|
|
self.assertTrue(datetimes_list[i] - datetimes_list[i-1] > timezone_timedelta(minutes=5))
|