Commit f25e2480 authored by Sean Bleier's avatar Sean Bleier

Added test for the connection pool

parent 234c0a82
......@@ -22,7 +22,8 @@ if not settings.configured:
'PASSWORD': 'yadayada',
},
},
}
},
ROOT_URLCONF = 'tests.urls',
)
from django.test.simple import DjangoTestSuiteRunner
......
......@@ -20,3 +20,5 @@ CACHES = {
},
},
}
ROOT_URLCONF = 'tests.urls'
\ No newline at end of file
# -*- coding: utf-8 -*-
import time
import unittest
try:
import cPickle as pickle
......@@ -9,6 +8,7 @@ except ImportError:
import pickle
from django import VERSION
from django.core.cache import get_cache
from django.test import TestCase
from models import Poll, expensive_calculation
from redis_cache.cache import RedisCache
......@@ -19,7 +19,7 @@ class C:
def m(n):
return 24
class RedisCacheTests(unittest.TestCase):
class RedisCacheTests(TestCase):
"""
A common set of tests derived from Django's own cache tests
......@@ -302,6 +302,26 @@ class RedisCacheTests(unittest.TestCase):
self.assertEqual(self.cache.get(old_key), None)
self.assertEqual(self.cache.get(new_key), 'spam')
def test_connection_pool(self):
# First, let's make sure that one connection exists in the pool
self.assertEqual(self.cache._cache.connection_pool._created_connections, 1)
# Now, let's tie up two connections in the pool.
c1 = self.cache._cache.connection_pool.get_connection("_")
self.assertEqual(self.cache._cache.connection_pool._created_connections, 1)
c2 = self.cache._cache.connection_pool.get_connection("_")
self.assertEqual(self.cache._cache.connection_pool._created_connections, 2)
# with 2 connections tied up, lets access a view makes sure it creates
# another connection
self.client.get("/")
self.assertEqual(self.cache._cache.connection_pool._created_connections, 3)
# The previous request releases the connection, let's call the view again
# and make sure that only 3 connections are created
self.client.get("/")
self.assertEqual(self.cache._cache.connection_pool._created_connections, 3)
if __name__ == '__main__':
unittest.main()
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^$', 'tests.views.someview'),
)
\ No newline at end of file
from django.core.cache import get_cache
from django.http import HttpResponse
def someview(request):
cache = get_cache('redis_cache.cache://127.0.0.1')
cache.set("foo", "bar")
return HttpResponse("Pants")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment