forked from matrix-org/synapse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix MAU reaping where reserved users are specified. (matrix-org#6168)
- Loading branch information
1 parent
83d8610
commit a0d0ba7
Showing
4 changed files
with
115 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix monthly active user reaping where reserved users are specified. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ def test_initialise_reserved_users(self): | |
{"medium": "email", "address": user2_email}, | ||
{"medium": "email", "address": user3_email}, | ||
] | ||
self.hs.config.mau_limits_reserved_threepids = threepids | ||
# -1 because user3 is a support user and does not count | ||
user_num = len(threepids) - 1 | ||
|
||
|
@@ -84,6 +85,7 @@ def test_initialise_reserved_users(self): | |
self.hs.config.max_mau_value = 0 | ||
|
||
self.reactor.advance(FORTY_DAYS) | ||
self.hs.config.max_mau_value = 5 | ||
|
||
self.store.reap_monthly_active_users() | ||
self.pump() | ||
|
@@ -147,9 +149,7 @@ def test_reap_monthly_active_users(self): | |
self.store.reap_monthly_active_users() | ||
self.pump() | ||
count = self.store.get_monthly_active_count() | ||
self.assertEquals( | ||
self.get_success(count), initial_users - self.hs.config.max_mau_value | ||
) | ||
self.assertEquals(self.get_success(count), self.hs.config.max_mau_value) | ||
|
||
self.reactor.advance(FORTY_DAYS) | ||
self.store.reap_monthly_active_users() | ||
|
@@ -158,6 +158,44 @@ def test_reap_monthly_active_users(self): | |
count = self.store.get_monthly_active_count() | ||
self.assertEquals(self.get_success(count), 0) | ||
|
||
def test_reap_monthly_active_users_reserved_users(self): | ||
""" Tests that reaping correctly handles reaping where reserved users are | ||
present""" | ||
|
||
self.hs.config.max_mau_value = 5 | ||
initial_users = 5 | ||
reserved_user_number = initial_users - 1 | ||
threepids = [] | ||
for i in range(initial_users): | ||
user = "@user%d:server" % i | ||
email = "user%[email protected]" % i | ||
self.get_success(self.store.upsert_monthly_active_user(user)) | ||
threepids.append({"medium": "email", "address": email}) | ||
# Need to ensure that the most recent entries in the | ||
# monthly_active_users table are reserved | ||
now = int(self.hs.get_clock().time_msec()) | ||
if i != 0: | ||
self.get_success( | ||
self.store.register_user(user_id=user, password_hash=None) | ||
) | ||
self.get_success( | ||
self.store.user_add_threepid(user, "email", email, now, now) | ||
) | ||
|
||
self.hs.config.mau_limits_reserved_threepids = threepids | ||
self.store.runInteraction( | ||
"initialise", self.store._initialise_reserved_users, threepids | ||
) | ||
count = self.store.get_monthly_active_count() | ||
self.assertTrue(self.get_success(count), initial_users) | ||
|
||
users = self.store.get_registered_reserved_users() | ||
self.assertEquals(len(self.get_success(users)), reserved_user_number) | ||
|
||
self.get_success(self.store.reap_monthly_active_users()) | ||
count = self.store.get_monthly_active_count() | ||
self.assertEquals(self.get_success(count), self.hs.config.max_mau_value) | ||
|
||
def test_populate_monthly_users_is_guest(self): | ||
# Test that guest users are not added to mau list | ||
user_id = "@user_id:host" | ||
|
@@ -192,12 +230,13 @@ def test_populate_monthly_users_should_not_update(self): | |
|
||
def test_get_reserved_real_user_account(self): | ||
# Test no reserved users, or reserved threepids | ||
count = self.store.get_registered_reserved_users_count() | ||
self.assertEquals(self.get_success(count), 0) | ||
users = self.get_success(self.store.get_registered_reserved_users()) | ||
self.assertEquals(len(users), 0) | ||
# Test reserved users but no registered users | ||
|
||
user1 = "@user1:example.com" | ||
user2 = "@user2:example.com" | ||
|
||
user1_email = "[email protected]" | ||
user2_email = "[email protected]" | ||
threepids = [ | ||
|
@@ -210,8 +249,8 @@ def test_get_reserved_real_user_account(self): | |
) | ||
|
||
self.pump() | ||
count = self.store.get_registered_reserved_users_count() | ||
self.assertEquals(self.get_success(count), 0) | ||
users = self.get_success(self.store.get_registered_reserved_users()) | ||
self.assertEquals(len(users), 0) | ||
|
||
# Test reserved registed users | ||
self.store.register_user(user_id=user1, password_hash=None) | ||
|
@@ -221,8 +260,9 @@ def test_get_reserved_real_user_account(self): | |
now = int(self.hs.get_clock().time_msec()) | ||
self.store.user_add_threepid(user1, "email", user1_email, now, now) | ||
self.store.user_add_threepid(user2, "email", user2_email, now, now) | ||
count = self.store.get_registered_reserved_users_count() | ||
self.assertEquals(self.get_success(count), len(threepids)) | ||
|
||
users = self.get_success(self.store.get_registered_reserved_users()) | ||
self.assertEquals(len(users), len(threepids)) | ||
|
||
def test_support_user_not_add_to_mau_limits(self): | ||
support_user_id = "@support:test" | ||
|