Commit dfd1873b authored by Jérome Perrin's avatar Jérome Perrin

*: replace erp5_site_global_id by a mechanism in test framework

erp5_site_global_id was from the tiolive time, when we were using ERP5
with mariadb and memcached instances shared by many zope instances, this
was used as a way to implement namespaces in memcached, to prevent
conflicts such as two different zope using the same cache keys.

Nowadays, we no longer share memcached, each ERP5 instance has its own
memcached and this prefixing is no longer needed, but there is still one
exception, when we run test using runTestSuite with --node_quantity
higher than 1, we have multiple running test instances sharing the same
mariadb and the same memcached. In that case, each test instance
uses a different mariadb database, but the risk of conflict remain for
memcached.

To solve this, we introduce a prefix for keys, choosen randomly at test
startup.

This was more or less what the current implementation was trying to do,
but we were setting erp5_site_global_id on the wrong object, so it was
not working since 4889d523 (Define property's default value at class
level., 2012-12-31). Also, this was only done at the level of SharedDict,
but some APIs such as CacheTool or SessionTool use MemcachedDict
directly. There was other problems that using the sql connection string
encoded in base64 was a too long prefix, because memcached are limited
in size. Also it was not preventing collisions when running tests on
the same test node, each runUnitTest execution was still having
pollution from the previous runUnitTest.
parent a51637b5
......@@ -5,7 +5,6 @@
#
##############################################################################
import random
import transaction
from Products.ERP5Type.tests.SecurityTestCase import SecurityTestCase
from Products.ERP5Type.tests.utils import DummyMailHost
......@@ -67,11 +66,6 @@ class TestOfficeJSSDKConfigurator(SecurityTestCase):
# Execute the business configuration if not installed
business_configuration = self.getBusinessConfiguration()
if (business_configuration.getSimulationState() != 'installed'):
self.portal.portal_caches.erp5_site_global_id = '%s' % random.random()
self.portal.portal_caches._p_changed = 1
self.commit()
self.portal.portal_caches.updateCache()
self.bootstrapSite()
self.commit()
......
......@@ -27,7 +27,6 @@
#
##############################################################################
import random
import unittest
from Products.ERP5Type.tests.ERP5TypeFunctionalTestCase import \
......@@ -91,11 +90,6 @@ class TestZeleniumStandaloneUserTutorial(ERP5TypeFunctionalTestCase):
# Execute the business configuration if not installed
business_configuration = self.getBusinessConfiguration()
if (business_configuration.getSimulationState() != 'installed'):
self.portal.portal_caches.erp5_site_global_id = '%s' % random.random()
self.portal.portal_caches._p_changed = 1
self.commit()
self.portal.portal_caches.updateCache()
self.bootstrapSite()
self.commit()
......
......@@ -300,9 +300,6 @@ if memcache is not None:
if memcached_plugin is None:
raise ValueError('Memcached Plugin does not exists: %r' % (
plugin_path, ))
global_prefix = self.erp5_site_global_id
if global_prefix:
key_prefix = global_prefix + '_' + key_prefix
return SharedDict(memcached_plugin.getConnection(), prefix=key_prefix)
InitializeClass(MemcachedTool)
......
......@@ -7,7 +7,6 @@
__version__ = '0.3.0'
import base64
import errno
import os
import random
......@@ -1322,10 +1321,6 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
reindex=reindex,
create_activities=create_activities,
**kw)
sql = kw.get('erp5_sql_connection_string')
if sql:
app[portal_name]._setProperty('erp5_site_global_id',
base64.standard_b64encode(str2bytes(sql)))
if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - _start))
# Release locks
......@@ -1642,7 +1637,7 @@ optimize()
@onsetup
def fortify():
'''Add some extra checks that we don't have at runtime, not to slow down the
system.
system and adjust the system for unit test environment.
'''
# check that we don't store persistent objects in cache
from Products.ERP5Type.CachePlugins.BaseCache import CacheEntry
......@@ -1667,5 +1662,15 @@ def fortify():
activity_kw, *args, **kw)
Message.__init__ = __init__
# Inject a prefix to keys used by memcached, so that when we are running
# multiple runUnitTest process using the same memcached instance they don't
# have conflicting keys.
import Products.ERP5Type.Tool.MemcachedTool
original_encodeKey = Products.ERP5Type.Tool.MemcachedTool.encodeKey
prefix = str2bytes(''.join(random.sample(string.ascii_letters + string.digits, 6)))
def encodeKey(key):
return prefix + original_encodeKey(key)
Products.ERP5Type.Tool.MemcachedTool.encodeKey = encodeKey
fortify()
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