Commit a4194282 authored by Ivan Tyagov's avatar Ivan Tyagov

Increate method execution time to avoid false test failures.

parent 8994258f
...@@ -54,6 +54,7 @@ class TestCacheTool(ERP5TypeTestCase): ...@@ -54,6 +54,7 @@ class TestCacheTool(ERP5TypeTestCase):
cache_duration = 10 # second cache_duration = 10 # second
python_script_id = "testCachedMethod" python_script_id = "testCachedMethod"
nb_iterations = 60000
def getTitle(self): def getTitle(self):
return "Cache Tool" return "Cache Tool"
...@@ -236,12 +237,11 @@ return result ...@@ -236,12 +237,11 @@ return result
print "TESTING:", cf_name print "TESTING:", cf_name
# if the test fails because your machine is too fast, increase this value. # if the test fails because your machine is too fast, increase this value.
nb_iterations = 30000
result = 'a short value' result = 'a short value'
portal.portal_caches.clearCacheFactory(cf_name) portal.portal_caches.clearCacheFactory(cf_name)
## 1st call ## 1st call
start = time.time() start = time.time()
cached = my_cache(nb_iterations, cached = my_cache(self.nb_iterations,
portal_path=('', portal.getId()), portal_path=('', portal.getId()),
result=result) result=result)
end = time.time() end = time.time()
...@@ -252,7 +252,7 @@ return result ...@@ -252,7 +252,7 @@ return result
## 2nd call - should be cached now ## 2nd call - should be cached now
start = time.time() start = time.time()
cached = my_cache(nb_iterations, cached = my_cache(self.nb_iterations,
portal_path=('', portal.getId()), portal_path=('', portal.getId()),
result=result) result=result)
end = time.time() end = time.time()
...@@ -276,7 +276,7 @@ return result ...@@ -276,7 +276,7 @@ return result
## 1st call ## 1st call
start = time.time() start = time.time()
cached = my_cache(nb_iterations, cached = my_cache(self.nb_iterations,
portal_path=('', portal.getId()), portal_path=('', portal.getId()),
result=result) result=result)
end = time.time() end = time.time()
...@@ -290,20 +290,20 @@ return result ...@@ -290,20 +290,20 @@ return result
# Test delete method on CachingMethod # Test delete method on CachingMethod
print "\n\tCalculation time (3rd call)", calculation_time print "\n\tCalculation time (3rd call)", calculation_time
# fill the cache # fill the cache
cached = my_cache(nb_iterations, cached = my_cache(self.nb_iterations,
portal_path=('', portal.getId()), portal_path=('', portal.getId()),
result=result) result=result)
self.assertEquals(cached, result) self.assertEquals(cached, result)
# Purge the Caching Method # Purge the Caching Method
my_cache.delete(nb_iterations, my_cache.delete(self.nb_iterations,
portal_path=('', portal.getId()), portal_path=('', portal.getId()),
result=result) result=result)
transaction.commit() transaction.commit()
# Check that result is computed # Check that result is computed
start = time.time() start = time.time()
cached = my_cache(nb_iterations, cached = my_cache(self.nb_iterations,
portal_path=('', portal.getId()), portal_path=('', portal.getId()),
result=result) result=result)
end = time.time() end = time.time()
...@@ -335,7 +335,6 @@ return result ...@@ -335,7 +335,6 @@ return result
print "="*40 print "="*40
print "TESTING: Concurrent RamCache" print "TESTING: Concurrent RamCache"
portal = self.getPortal() portal = self.getPortal()
nb_iterations = 30000
result = 'Something short' result = 'Something short'
py_script_obj = getattr(portal, self.python_script_id) py_script_obj = getattr(portal, self.python_script_id)
...@@ -348,7 +347,7 @@ return result ...@@ -348,7 +347,7 @@ return result
'another_ram_cache_factory',)) 'another_ram_cache_factory',))
# First call, fill the cache # First call, fill the cache
start = time.time() start = time.time()
cached = ram_cached_method(nb_iterations, cached = ram_cached_method(self.nb_iterations,
portal_path=('', portal.getId()), portal_path=('', portal.getId()),
result=result) result=result)
end = time.time() end = time.time()
...@@ -359,7 +358,7 @@ return result ...@@ -359,7 +358,7 @@ return result
## 2nd call - should be cached now ## 2nd call - should be cached now
start = time.time() start = time.time()
cached = ram_cached_method(nb_iterations, cached = ram_cached_method(self.nb_iterations,
portal_path=('', portal.getId()), portal_path=('', portal.getId()),
result=result) result=result)
end = time.time() end = time.time()
...@@ -373,7 +372,7 @@ return result ...@@ -373,7 +372,7 @@ return result
portal.portal_caches.clearCacheFactory('another_ram_cache_factory') portal.portal_caches.clearCacheFactory('another_ram_cache_factory')
# Call conversion for ram_cache_factory # Call conversion for ram_cache_factory
start = time.time() start = time.time()
cached = ram_cached_method(nb_iterations, cached = ram_cached_method(self.nb_iterations,
portal_path=('', portal.getId()), portal_path=('', portal.getId()),
result=result) result=result)
end = time.time() end = time.time()
...@@ -416,7 +415,6 @@ veryExpensiveMethod(value) ...@@ -416,7 +415,6 @@ veryExpensiveMethod(value)
return 'a' * 1024 * 1024 * 25 return 'a' * 1024 * 1024 * 25
""" """
py_script_obj.ZPythonScript_edit(py_script_params, py_script_body) py_script_obj.ZPythonScript_edit(py_script_params, py_script_body)
nb_iterations = 30000
result = 'a' * 1024 * 1024 * 25 # 25 MB result = 'a' * 1024 * 1024 * 25 # 25 MB
long_parameter = 'a' * 1024 long_parameter = 'a' * 1024
...@@ -443,7 +441,7 @@ return 'a' * 1024 * 1024 * 25 ...@@ -443,7 +441,7 @@ return 'a' * 1024 * 1024 * 25
#First call, fill the cache #First call, fill the cache
start = time.time() start = time.time()
cached = cached_method(nb_iterations, cached = cached_method(self.nb_iterations,
long_parameter=long_parameter) long_parameter=long_parameter)
end = time.time() end = time.time()
calculation_time = end-start calculation_time = end-start
...@@ -456,7 +454,7 @@ return 'a' * 1024 * 1024 * 25 ...@@ -456,7 +454,7 @@ return 'a' * 1024 * 1024 * 25
## 2nd call - should be cached now ## 2nd call - should be cached now
start = time.time() start = time.time()
cached = cached_method(nb_iterations, cached = cached_method(self.nb_iterations,
long_parameter=long_parameter) long_parameter=long_parameter)
end = time.time() end = time.time()
calculation_time = end-start calculation_time = end-start
...@@ -472,7 +470,6 @@ return 'a' * 1024 * 1024 * 25 ...@@ -472,7 +470,6 @@ return 'a' * 1024 * 1024 * 25
print "="*40 print "="*40
print "TESTING: Cache Expiration Time" print "TESTING: Cache Expiration Time"
portal = self.getPortal() portal = self.getPortal()
nb_iterations = 30000
py_script_obj = getattr(portal, self.python_script_id) py_script_obj = getattr(portal, self.python_script_id)
...@@ -486,7 +483,7 @@ return 'a' * 1024 * 1024 * 25 ...@@ -486,7 +483,7 @@ return 'a' * 1024 * 1024 * 25
# First call, fill the cache # First call, fill the cache
start = time.time() start = time.time()
cached_method(nb_iterations, portal_path='something') cached_method(self.nb_iterations, portal_path='something')
transaction.commit() transaction.commit()
end = time.time() end = time.time()
calculation_time = end-start calculation_time = end-start
...@@ -495,7 +492,7 @@ return 'a' * 1024 * 1024 * 25 ...@@ -495,7 +492,7 @@ return 'a' * 1024 * 1024 * 25
## 2nd call - should be cached now ## 2nd call - should be cached now
start = time.time() start = time.time()
cached = cached_method(nb_iterations, portal_path='something') cached = cached_method(self.nb_iterations, portal_path='something')
transaction.commit() transaction.commit()
end = time.time() end = time.time()
calculation_time = end-start calculation_time = end-start
...@@ -510,7 +507,7 @@ return 'a' * 1024 * 1024 * 25 ...@@ -510,7 +507,7 @@ return 'a' * 1024 * 1024 * 25
# Call conversion for ram_cache_factory # Call conversion for ram_cache_factory
start = time.time() start = time.time()
cached = cached_method(nb_iterations, portal_path='something') cached = cached_method(self.nb_iterations, portal_path='something')
transaction.commit() transaction.commit()
end = time.time() end = time.time()
calculation_time = end-start calculation_time = end-start
......
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