Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
Django-Redis-Cache
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shared
Django-Redis-Cache
Commits
f25e2480
Commit
f25e2480
authored
Jun 17, 2011
by
Sean Bleier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test for the connection pool
parent
234c0a82
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
3 deletions
+40
-3
runtests.py
runtests.py
+2
-1
settings.py
tests/settings.py
+2
-0
tests.py
tests/testapp/tests.py
+22
-2
urls.py
tests/urls.py
+6
-0
views.py
tests/views.py
+8
-0
No files found.
runtests.py
View file @
f25e2480
...
...
@@ -22,7 +22,8 @@ if not settings.configured:
'PASSWORD'
:
'yadayada'
,
},
},
}
},
ROOT_URLCONF
=
'tests.urls'
,
)
from
django.test.simple
import
DjangoTestSuiteRunner
...
...
tests/settings.py
View file @
f25e2480
...
...
@@ -20,3 +20,5 @@ CACHES = {
},
},
}
ROOT_URLCONF
=
'tests.urls'
\ No newline at end of file
tests/testapp/tests.py
View file @
f25e2480
# -*- 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
()
tests/urls.py
0 → 100644
View file @
f25e2480
from
django.conf.urls.defaults
import
*
urlpatterns
=
patterns
(
''
,
(
r'^$'
,
'tests.views.someview'
),
)
\ No newline at end of file
tests/views.py
0 → 100644
View file @
f25e2480
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment