Skip to content

Commit

Permalink
add tests for redis, memcached
Browse files Browse the repository at this point in the history
  • Loading branch information
krav committed Mar 21, 2022
1 parent 6067a83 commit 41467d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion tests/unit/clients/memcache_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/clients/redis_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(
{
Expand Down

0 comments on commit 41467d3

Please sign in to comment.