Commit bd852c73 authored by Nicolas Delaby's avatar Nicolas Delaby

Test new duration_time parameter of MemcachedTool

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34781 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent eb519a76
No related merge requests found
......@@ -34,6 +34,7 @@ import transaction
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.utils import installRealMemcachedTool
import time
class TestMemcachedTool(ERP5TypeTestCase):
"""
......@@ -43,6 +44,8 @@ class TestMemcachedTool(ERP5TypeTestCase):
memcached server.
"""
expiration_time = 10 # second
def getBusinessTemplateList(self):
return tuple()
......@@ -59,6 +62,13 @@ class TestMemcachedTool(ERP5TypeTestCase):
portal_type='Memcached Plugin',
int_index=0,
url_string='127.0.0.1:11211')
if getattr(memcached_tool, 'memcached_plugin_with_expiration', None) is None:
memcached_tool.newContent(id='memcached_plugin_with_expiration',
portal_type='Memcached Plugin',
int_index=1,
expiration_time=self.expiration_time,
url_string='127.0.0.1:11211')
transaction.commit()
self.tic()
......@@ -75,6 +85,12 @@ class TestMemcachedTool(ERP5TypeTestCase):
return self.getPortal().portal_memcached.getMemcachedDict(key_prefix='unit_test',
plugin_path='portal_memcached/default_memcached_plugin')
def getMemcachedDictWithExpiration(self):
return self.getPortal().portal_memcached.getMemcachedDict(
key_prefix='unit_test',
plugin_path='portal_memcached/memcached_plugin_with_expiration')
def test_00_MemcachedToolIsEnabled(self):
"""
Check if MemcachedTool is enabled without USE_MEMCACHED_TOOL file.
......@@ -183,5 +199,21 @@ class TestMemcachedTool(ERP5TypeTestCase):
else:
self.fail('No error was raised when assigning a value to a non-string key.')
def test_07_checkExpirationTimeOfMemcachedDict(self):
"""
Test that expiration time parameter is well handle by memcached tool
"""
tested_dict = self.getMemcachedDictWithExpiration()
key = 'my_key'
value = 'a'*100
tested_dict[key] = value
transaction.commit()
self.assertEquals(tested_dict.get(key), value)
transaction.commit()
# Sleep 10s
time.sleep(self.expiration_time)
# now value should have expired
self.assertRaises(KeyError, tested_dict.__getitem__, key)
if __name__ == '__main__':
unittest.main()
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