Permalink
Browse files

Adding test to prove multiple connections are being formed when acces…

…sing multiple backends. Thanks to @twidi for the report and jezdez for the kick in the pants.
  • Loading branch information...
sebleier committed May 16, 2012
1 parent 17d8ab6 commit 4156cdc576bf7c132ad83df93a126110bbce3fed
Showing with 14 additions and 2 deletions.
  1. +1 −0 redis_cache/cache.py
  2. +13 −2 tests/testapp/tests.py
View
@@ -17,6 +17,7 @@
from redis.connection import UnixDomainSocketConnection, Connection
from redis.connection import DefaultParser
+
class CacheKey(object):
"""
A stub string class that we can use to check if a key was created already.
View
@@ -10,9 +10,10 @@
from django.core.cache import get_cache
from django.test import TestCase
from models import Poll, expensive_calculation
-from redis_cache.cache import RedisCache, ImproperlyConfigured
+from redis_cache.cache import RedisCache, ImproperlyConfigured, pool
from redis.connection import UnixDomainSocketConnection
+
# functions/classes for complex data type tests
def f():
return 42
@@ -60,7 +61,7 @@ def test_default_initialization(self):
if connection_class is not UnixDomainSocketConnection:
self.assertEqual(self.cache._client.connection_pool.connection_kwargs['host'], '127.0.0.1')
self.assertEqual(self.cache._client.connection_pool.connection_kwargs['port'], 6379)
- self.assertEqual(self.cache._client.connection_pool.connection_kwargs['db'], 15)
+ self.assertEqual(self.cache._client.connection_pool.connection_kwargs['db'], 1)
def test_simple(self):
# Simple cache set/get works
@@ -346,5 +347,15 @@ def test_string_float_caching(self):
a = self.cache.get('a')
self.assertEqual(a, 1.1)
+ def test_multiple_connection_pool_connections(self):
+ pool._connection_pools = {}
+ c1 = get_cache('redis_cache.cache://127.0.0.1:6379?db=15')
+ self.assertEqual(len(pool._connection_pools), 1)
+ c2 = get_cache('redis_cache.cache://127.0.0.1:6379?db=14')
+ self.assertEqual(len(pool._connection_pools), 2)
+ c3 = get_cache('redis_cache.cache://127.0.0.1:6379?db=15')
+ self.assertEqual(len(pool._connection_pools), 2)
+
+
if __name__ == '__main__':
unittest.main()

0 comments on commit 4156cdc

Please sign in to comment.