From 41467d39d8ce7345f4dcca1dd1720d66bf5dd31b Mon Sep 17 00:00:00 2001 From: Kris La Date: Mon, 21 Mar 2022 17:54:49 +0100 Subject: [PATCH] add tests for redis, memcached --- tests/unit/clients/memcache_tests.py | 12 +++++++++++- tests/unit/clients/redis_tests.py | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/unit/clients/memcache_tests.py b/tests/unit/clients/memcache_tests.py index fd6afa9a9..656ee923a 100644 --- a/tests/unit/clients/memcache_tests.py +++ b/tests/unit/clients/memcache_tests.py @@ -11,7 +11,7 @@ del pymemcache from baseplate.lib.config import ConfigurationError -from baseplate.clients.memcache import pool_from_config +from baseplate.clients.memcache import pool_from_config, MemcacheContextFactory from baseplate.clients.memcache import lib as memcache_lib @@ -54,6 +54,16 @@ def test_nodelay(self): ) self.assertEqual(pool.no_delay, False) + def test_metrics(self): + max_pool_size = "123" + ctx = MemcacheContextFactory( + pool_from_config( + {"memcache.endpoint": "localhost:1234", "memcache.max_pool_size": max_pool_size} + ) + ) + metric = ctx.promTotalConnections.collect() + self.assertEqual(metric[0].samples[0].value, float(max_pool_size)) + class SerdeTests(unittest.TestCase): def test_serialize_str(self): diff --git a/tests/unit/clients/redis_tests.py b/tests/unit/clients/redis_tests.py index 046b6859f..30c1fca77 100644 --- a/tests/unit/clients/redis_tests.py +++ b/tests/unit/clients/redis_tests.py @@ -8,7 +8,7 @@ del redis from baseplate.lib.config import ConfigurationError -from baseplate.clients.redis import pool_from_config +from baseplate.clients.redis import pool_from_config, RedisContextFactory class PoolFromConfigTests(unittest.TestCase): @@ -23,6 +23,16 @@ def test_basic_url(self): self.assertEqual(pool.connection_kwargs["port"], 1234) self.assertEqual(pool.connection_kwargs["db"], 0) + def test_metrics(self): + max_connections = "123" + ctx = RedisContextFactory( + pool_from_config( + {"redis.url": "redis://localhost:1234/0", "redis.max_connections": max_connections} + ) + ) + metric = ctx.totalConnections.collect() + self.assertEqual(metric[0].samples[0].value, float(max_connections)) + def test_timeouts(self): pool = pool_from_config( {