summary refs log tree commit diff
path: root/tests/config
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2023-08-30 00:39:39 +0100
committerGitHub <noreply@github.com>2023-08-30 00:39:39 +0100
commit62a1a9be52f4bc79b112f9841ddb3d03b8efccba (patch)
tree36a76a4b81b829f700f7c6edd36e009b688c9734 /tests/config
parentTrack currently syncing users by device for presence (#16172) (diff)
downloadsynapse-62a1a9be52f4bc79b112f9841ddb3d03b8efccba.tar.xz
Describe which rate limiter was hit in logs (#16135)
Diffstat (limited to '')
-rw-r--r--tests/config/test_ratelimiting.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/config/test_ratelimiting.py b/tests/config/test_ratelimiting.py
index f12147eaa0..0c27dd21e2 100644
--- a/tests/config/test_ratelimiting.py
+++ b/tests/config/test_ratelimiting.py
@@ -12,11 +12,42 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 from synapse.config.homeserver import HomeServerConfig
+from synapse.config.ratelimiting import RatelimitSettings
 
 from tests.unittest import TestCase
 from tests.utils import default_config
 
 
+class ParseRatelimitSettingsTestcase(TestCase):
+    def test_depth_1(self) -> None:
+        cfg = {
+            "a": {
+                "per_second": 5,
+                "burst_count": 10,
+            }
+        }
+        parsed = RatelimitSettings.parse(cfg, "a")
+        self.assertEqual(parsed, RatelimitSettings("a", 5, 10))
+
+    def test_depth_2(self) -> None:
+        cfg = {
+            "a": {
+                "b": {
+                    "per_second": 5,
+                    "burst_count": 10,
+                },
+            }
+        }
+        parsed = RatelimitSettings.parse(cfg, "a.b")
+        self.assertEqual(parsed, RatelimitSettings("a.b", 5, 10))
+
+    def test_missing(self) -> None:
+        parsed = RatelimitSettings.parse(
+            {}, "a", defaults={"per_second": 5, "burst_count": 10}
+        )
+        self.assertEqual(parsed, RatelimitSettings("a", 5, 10))
+
+
 class RatelimitConfigTestCase(TestCase):
     def test_parse_rc_federation(self) -> None:
         config_dict = default_config("test")