test_remote_counts: Insert in date order.

Inserting these in order means that they have dates which ascend with
their ids and remote_ids, for a more accurate simulation.
This commit is contained in:
Alex Vandiver 2023-11-28 06:12:09 +00:00 committed by Tim Abbott
parent 82960d9bc2
commit f4cbb494ac
1 changed files with 43 additions and 40 deletions

View File

@ -51,51 +51,54 @@ class RemoteCountTest(ZulipTestCase):
# we actually don't record 0s), then the function should just very reasonably return 0.
self.assertEqual(compute_max_monthly_messages(self.server), 0)
# Last 30 days of data:
# We insert these oldest-first so that the ids are in a
# realistic order. This is >90 days ago and should be ignored
# for the calculation. We simulate the highest amounts of
# messages here, to test that this is indeed ignored.
RemoteInstallationCount.objects.bulk_create(
RemoteInstallationCount(
server=self.server,
remote_id=1,
property="messages_sent:message_type:day",
value=10,
end_time=now_offset - datetime.timedelta(days=t),
)
for t in range(1, 31)
)
# 30 days before that:
# This will be the peak of the last 3 months - with 900 messages total
RemoteInstallationCount.objects.bulk_create(
RemoteInstallationCount(
server=self.server,
remote_id=1,
property="messages_sent:message_type:day",
value=30,
end_time=now_offset - datetime.timedelta(days=30 + t),
)
for t in range(1, 31)
)
# Additional 30 days before that:
# This is the last month we're considering for the calculation
RemoteInstallationCount.objects.bulk_create(
RemoteInstallationCount(
server=self.server,
remote_id=1,
property="messages_sent:message_type:day",
value=20,
end_time=now_offset - datetime.timedelta(days=60 + t),
)
for t in range(1, 31)
)
# Additional 30 days before that:
# This is >90 days ago and should be ignored for the calculation. We simulate the highest
# amounts of messages here, to test that this is indeed ignored.
RemoteInstallationCount.objects.bulk_create(
RemoteInstallationCount(
server=self.server,
remote_id=1,
remote_id=1 + t,
property="messages_sent:message_type:day",
value=100,
end_time=now_offset - datetime.timedelta(days=90 + t),
end_time=now_offset - datetime.timedelta(days=90 + (31 - t)),
)
for t in range(1, 31)
)
# Days 60 - 89 ago; this is the last month we're considering for
# the calculation
RemoteInstallationCount.objects.bulk_create(
RemoteInstallationCount(
server=self.server,
remote_id=31 + t,
property="messages_sent:message_type:day",
value=20,
end_time=now_offset - datetime.timedelta(days=60 + (31 - t)),
)
for t in range(1, 31)
)
# Days 30 - 59 ago: this will be the peak of the last 3 months -
# with 900 messages total
RemoteInstallationCount.objects.bulk_create(
RemoteInstallationCount(
server=self.server,
remote_id=61 + t,
property="messages_sent:message_type:day",
value=30,
end_time=now_offset - datetime.timedelta(days=30 + (31 - t)),
)
for t in range(1, 31)
)
# Days 0 - 29 ago:
RemoteInstallationCount.objects.bulk_create(
RemoteInstallationCount(
server=self.server,
remote_id=91 + t,
property="messages_sent:message_type:day",
value=10,
end_time=now_offset - datetime.timedelta(days=(31 - t)),
)
for t in range(1, 31)
)