Commit 6cc7f587 authored by Julien Muchembled's avatar Julien Muchembled

runUnitTest: new option to randomize priorities of activities in a deterministic way

Most random failures in unit tests are due to wrong dependencies between
activities. With this option, it is often possible to make a unit test
reproducible to make debugging easier.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34432 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b8d540f3
......@@ -1331,5 +1331,17 @@ def fortify():
dumps(value)
CacheEntry__init__(self, value, *args, **kw)
CacheEntry.__init__ = __init__
# randomize priorities of activities in a deterministic way
seed = os.environ.get("random_activity_priority")
if seed is not None:
ZopeTestCase._print("RNG seed for priorities of activities is %r\n" % seed)
rng = random.Random(seed)
from Products.CMFActivity.ActivityTool import Message
Message__init__ = Message.__init__
def __init__(self, obj, active_process, activity_kw, *args, **kw):
activity_kw['priority'] = rng.randint(-128, 127)
Message__init__(self, obj, active_process, activity_kw, *args, **kw)
Message.__init__ = __init__
fortify()
......@@ -8,6 +8,7 @@ import getopt
import unittest
import shutil
import errno
import random
import backportUnittest
......@@ -79,21 +80,28 @@ Options:
for performance reasons. Provide list of documents
(delimited with comas) for which we want to force
indexing. This can only be for now 'portal_types'
--conversion_server_hostname=STRING
Hostname used to connect to conversion server (Oood),
this value will stored at default preference. By default
localhost is used.
Hostname used to connect to conversion server (Oood),
this value will stored at default preference.
By default localhost is used.
--conversion_server_port=STRING
Port number used to connect to conversion server
(Oood), the value will be stored at default preference.
By default 8008 is used.
Port number used to connect to conversion server
(Oood), the value will be stored at default preference.
By default 8008 is used.
--use_dummy_mail_host
Replace the MailHost by DummyMailHost. This prevent
the instance send emails. By default Original MailHost
is used.
Replace the MailHost by DummyMailHost.
This prevent the instance send emails.
By default Original MailHost is used.
--random_activity_priority=[SEED]
Force activities to have a random priority, to make
random failures (due to bad activity dependencies)
almost always reproducible. A random number
generator with the specified seed (or a random one
otherwise) is created for this purpose.
"""
......@@ -515,12 +523,14 @@ def main():
"enable_full_indexing=",
"run_only=",
"update_only=",
"use_dummy_mail_host",
"update_business_templates"] )
"use_dummy_mail_host",
"update_business_templates",
"random_activity_priority=",
])
except getopt.GetoptError, msg:
usage(sys.stderr, msg)
sys.exit(2)
if WIN:
os.environ["erp5_tests_bt5_path"] = os.path.join(real_instance_home, 'bt5')
......@@ -582,6 +592,9 @@ def main():
os.environ["conversion_server_port"] = arg
elif opt == "--use_dummy_mail_host":
os.environ["use_dummy_mail_host"] = "1"
elif opt == "--random_activity_priority":
os.environ["random_activity_priority"] = arg or \
str(random.randrange(0, 1<<16))
test_list = args
if not test_list:
......
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