mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-09 05:32:11 -04:00
Option to suppress resource exceeded alerting (#6173)
The expected use case is to suppress MAU limiting on small instances
This commit is contained in:
parent
92e88a71d3
commit
2794b79052
8 changed files with 160 additions and 46 deletions
|
@ -17,7 +17,7 @@ from mock import Mock
|
|||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.constants import EventTypes, ServerNoticeMsgType
|
||||
from synapse.api.constants import EventTypes, LimitBlockingTypes, ServerNoticeMsgType
|
||||
from synapse.api.errors import ResourceLimitError
|
||||
from synapse.server_notices.resource_limits_server_notices import (
|
||||
ResourceLimitsServerNotices,
|
||||
|
@ -133,7 +133,7 @@ class TestResourceLimitsServerNotices(unittest.HomeserverTestCase):
|
|||
self.get_success(self._rlsn.maybe_send_server_notice_to_user(self.user_id))
|
||||
|
||||
# Would be better to check contents, but 2 calls == set blocking event
|
||||
self.assertTrue(self._send_notice.call_count == 2)
|
||||
self.assertEqual(self._send_notice.call_count, 2)
|
||||
|
||||
def test_maybe_send_server_notice_to_user_add_blocked_notice_noop(self):
|
||||
"""
|
||||
|
@ -158,6 +158,61 @@ 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_limit_alerting = False
|
||||
self._rlsn._auth.check_auth_blocking = Mock(
|
||||
side_effect=ResourceLimitError(
|
||||
403, "foo", limit_type=LimitBlockingTypes.MONTHLY_ACTIVE_USER
|
||||
)
|
||||
)
|
||||
self.get_success(self._rlsn.maybe_send_server_notice_to_user(self.user_id))
|
||||
|
||||
self.assertTrue(self._send_notice.call_count == 0)
|
||||
|
||||
def test_check_hs_disabled_unaffected_by_mau_alert_suppression(self):
|
||||
"""
|
||||
Test that when a server is disabled, that MAU limit alerting is ignored.
|
||||
"""
|
||||
self.hs.config.mau_limit_alerting = False
|
||||
self._rlsn._auth.check_auth_blocking = Mock(
|
||||
side_effect=ResourceLimitError(
|
||||
403, "foo", limit_type=LimitBlockingTypes.HS_DISABLED
|
||||
)
|
||||
)
|
||||
self.get_success(self._rlsn.maybe_send_server_notice_to_user(self.user_id))
|
||||
|
||||
# Would be better to check contents, but 2 calls == set blocking event
|
||||
self.assertEqual(self._send_notice.call_count, 2)
|
||||
|
||||
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_limit_alerting = False
|
||||
self._rlsn._auth.check_auth_blocking = Mock(
|
||||
side_effect=ResourceLimitError(
|
||||
403, "foo", limit_type=LimitBlockingTypes.MONTHLY_ACTIVE_USER
|
||||
)
|
||||
)
|
||||
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue