Commit 9bb3a736 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 use derive a prefix from mariadb connection string
and use it in memcached.

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.

Also, there was a problem that we did not notice yet, because the
previous implementation was doing nothing: memcached keys are limited in
size, to overcome this, we don't use the full connection string in
base64 (which is around 70 characters), but a short hash of the
connection string.
parent fff85e8d
Pipeline #38843 passed with stage
in 0 seconds
......@@ -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
......@@ -1317,10 +1316,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
......@@ -1637,7 +1632,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
......@@ -1662,5 +1657,18 @@ 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
erp5_sql_connection_string = os.environ.get('erp5_sql_connection_string')
if erp5_sql_connection_string:
test_prefix = md5(
str2bytes(erp5_sql_connection_string)).hexdigest()[:6].encode()
def encodeKey(key):
return test_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