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(): ...@@ -1331,5 +1331,17 @@ def fortify():
dumps(value) dumps(value)
CacheEntry__init__(self, value, *args, **kw) CacheEntry__init__(self, value, *args, **kw)
CacheEntry.__init__ = __init__ 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() fortify()
...@@ -8,6 +8,7 @@ import getopt ...@@ -8,6 +8,7 @@ import getopt
import unittest import unittest
import shutil import shutil
import errno import errno
import random
import backportUnittest import backportUnittest
...@@ -82,8 +83,8 @@ Options: ...@@ -82,8 +83,8 @@ Options:
--conversion_server_hostname=STRING --conversion_server_hostname=STRING
Hostname used to connect to conversion server (Oood), Hostname used to connect to conversion server (Oood),
this value will stored at default preference. By default this value will stored at default preference.
localhost is used. By default localhost is used.
--conversion_server_port=STRING --conversion_server_port=STRING
Port number used to connect to conversion server Port number used to connect to conversion server
...@@ -91,9 +92,16 @@ Options: ...@@ -91,9 +92,16 @@ Options:
By default 8008 is used. By default 8008 is used.
--use_dummy_mail_host --use_dummy_mail_host
Replace the MailHost by DummyMailHost. This prevent Replace the MailHost by DummyMailHost.
the instance send emails. By default Original MailHost This prevent the instance send emails.
is used. 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.
""" """
...@@ -516,7 +524,9 @@ def main(): ...@@ -516,7 +524,9 @@ def main():
"run_only=", "run_only=",
"update_only=", "update_only=",
"use_dummy_mail_host", "use_dummy_mail_host",
"update_business_templates"] ) "update_business_templates",
"random_activity_priority=",
])
except getopt.GetoptError, msg: except getopt.GetoptError, msg:
usage(sys.stderr, msg) usage(sys.stderr, msg)
sys.exit(2) sys.exit(2)
...@@ -582,6 +592,9 @@ def main(): ...@@ -582,6 +592,9 @@ def main():
os.environ["conversion_server_port"] = arg os.environ["conversion_server_port"] = arg
elif opt == "--use_dummy_mail_host": elif opt == "--use_dummy_mail_host":
os.environ["use_dummy_mail_host"] = "1" 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 test_list = args
if not test_list: 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