summary refs log tree commit diff
diff options
context:
space:
mode:
authorNeil Johnson <neil@fragile.org.uk>2019-10-10 23:39:14 +0100
committerNeil Johnson <neil@fragile.org.uk>2019-10-10 23:39:14 +0100
commite4e4364b57794cbd3580270a2e395d6e6bca5ad9 (patch)
treec2865f8fa76a4bdbe47abf0684c706d215e971ec
parentwip commit to suppress mau alerting for small instances (diff)
downloadsynapse-e4e4364b57794cbd3580270a2e395d6e6bca5ad9.tar.xz
switch config to a bool and write tests
-rw-r--r--synapse/config/server.py9
-rw-r--r--synapse/server_notices/resource_limits_server_notices.py5
-rw-r--r--tests/server_notices/test_resource_limits_server_notices.py35
3 files changed, 40 insertions, 9 deletions
diff --git a/synapse/config/server.py b/synapse/config/server.py
index 9df21b4acb..8b1b5af312 100644
--- a/synapse/config/server.py
+++ b/synapse/config/server.py
@@ -169,7 +169,7 @@ class ServerConfig(Config):
         )
 
         self.mau_trial_days = config.get("mau_trial_days", 0)
-        self.mau_alerting_threshold = config.get('mau_alerting_threshold', 0)
+        self.mau_suppress_alerting = config.get('mau_suppress_alerting', False)
 
         # How long to keep redacted events in the database in unredacted form
         # before redacting them.
@@ -694,16 +694,15 @@ class ServerConfig(Config):
         # sign up in a short space of time never to return after their initial
         # session.
         #
-        # 'mau_alerting_threshold' is a means of limiting client side alerting
+        # 'mau_suppress_alerting' is a means of limiting client side alerting
         # should the mau limit be reached. This is useful for small instances
         # where the admin has 5 mau seats (say) for 5 specific people and no
-        # interest increasing the mau limit further. Defaults to 0 which denotes
-        # that the option is disabled.
+        # interest increasing the mau limit further. Defaults to False.
         #
         #limit_usage_by_mau: False
         #max_mau_value: 50
         #mau_trial_days: 2
-        #mau_alerting_threshold: 10
+        #mau_suppress_alerting: True
 
         # If enabled, the metrics for the number of monthly active users will
         # be populated, however no one will be limited. If limit_usage_by_mau
diff --git a/synapse/server_notices/resource_limits_server_notices.py b/synapse/server_notices/resource_limits_server_notices.py
index 57228e0caa..8229a4de43 100644
--- a/synapse/server_notices/resource_limits_server_notices.py
+++ b/synapse/server_notices/resource_limits_server_notices.py
@@ -91,10 +91,7 @@ class ResourceLimitsServerNotices(object):
         currently_blocked, ref_events = yield self._is_room_currently_blocked(room_id)
 
         try:
-            if (
-                self._config.mau_alerting_threshold > 0
-                and self._config.mau_alerting_threshold > self._config.max_mau_value
-            ):
+            if self._config.mau_suppress_alerting:
                 # Alerting disabled, reset room if necessary and return
                 if currently_blocked:
                     content = {"pinned": ref_events}
diff --git a/tests/server_notices/test_resource_limits_server_notices.py b/tests/server_notices/test_resource_limits_server_notices.py
index cdf89e3383..e6928c9c26 100644
--- a/tests/server_notices/test_resource_limits_server_notices.py
+++ b/tests/server_notices/test_resource_limits_server_notices.py
@@ -158,6 +158,41 @@ class TestResourceLimitsServerNotices(unittest.HomeserverTestCase):
 
         self._send_notice.assert_not_called()
 
+    def test_maybe_send_server_notice_when_alerting_suppressed_room_unblocked(self):
+        """
+        Test that when server is over MAU limit and alerting is suppressed, then
+        an alert message is not sent into the room
+        """
+        self.hs.config.mau_suppress_alerting = True
+        self._rlsn._auth.check_auth_blocking = Mock(
+            side_effect=ResourceLimitError(403, "foo")
+        )
+        self.get_success(self._rlsn.maybe_send_server_notice_to_user(self.user_id))
+
+        self.assertTrue(self._send_notice.call_count == 0)
+
+    def test_maybe_send_server_notice_when_alerting_suppressed_room_blocked(self):
+        """
+        When the room is already in a blocked state, test that when alerting
+        is suppressed that the room is returned to an unblocked state.
+        """
+        self.hs.config.mau_suppress_alerting = True
+        self._rlsn._auth.check_auth_blocking = Mock(
+            side_effect=ResourceLimitError(403, "foo")
+        )
+        self._rlsn._server_notices_manager.__is_room_currently_blocked = Mock(
+            return_value=defer.succeed((True, []))
+        )
+
+        mock_event = Mock(
+            type=EventTypes.Message, content={"msgtype": ServerNoticeMsgType}
+        )
+        self._rlsn._store.get_events = Mock(
+            return_value=defer.succeed({"123": mock_event})
+        )
+        self.get_success(self._rlsn.maybe_send_server_notice_to_user(self.user_id))
+
+        self._send_notice.assert_called_once()
 
 class TestResourceLimitsServerNoticesWithRealRooms(unittest.HomeserverTestCase):
     def prepare(self, reactor, clock, hs):