Commit 737b9675 authored by Jérome Perrin's avatar Jérome Perrin Committed by Kazuhiko Shiozaki

testCMFActivity: support pickle protocol > 0 in test_insert_max_payload

This test assumed that activating a method with a string of length `n+x`
as argument would be serialized in `x` more bytes that activating the
same method with a string of length `n` as argument, which is only true
for protocol 0 for multiple reasons ( short strings and long strings
are serialized differently, "frames" are used with protocol 5) and
db.string_literal seems to introduce a difference.

Change the test to mock Message.dump to produce longer dumps instead of
relying on this assumption.
parent 032517c8
...@@ -1902,18 +1902,30 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1902,18 +1902,30 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
activity_tool.activate(activity=activity, group_id=str(i) activity_tool.activate(activity=activity, group_id=str(i)
).doSomething(arg) ).doSomething(arg)
activity_tool.activate(activity=activity, group_id='~' activity_tool.activate(activity=activity, group_id='~'
).doSomething(' ' * n) ).doSomething(last_message_arg)
self.tic() self.tic()
self.assertEqual(len(invoke_list), N) self.assertEqual(len(invoke_list), N)
invoke_list.remove(n) invoke_list.remove(len(last_message_arg))
self.assertEqual(set(invoke_list), {len(arg)}) self.assertEqual(set(invoke_list), {len(arg)})
del invoke_list[:] del invoke_list[:]
activity_tool.__class__.doSomething = \ activity_tool.__class__.doSomething = \
lambda self, arg: invoke_list.append(len(arg)) lambda self, arg: invoke_list.append(len(arg))
original_dump = Message.dump
def dump(m):
dumped = original_dump(m)
if m.args == (last_message_arg, ):
dumped += b' ' * n
return dumped
Message.dump = staticmethod(dump)
try: try:
DB.query = query DB.query = query
for activity in ActivityTool.activity_dict: for activity in ActivityTool.activity_dict:
# We'll activate N-1 times with `arg`, which is a long string that
# should produce large messsage dumps and 1 time with
# `last_message_arg`, for which dump is patched to artificially
# produce a message dump `n` bytes longer than usual.
arg = ' ' * (max_allowed_packet // N) arg = ' ' * (max_allowed_packet // N)
last_message_arg = 'last'
# Find the size of the last message argument, such that all messages # Find the size of the last message argument, such that all messages
# are inserted in a single query whose size is to the maximum allowed. # are inserted in a single query whose size is to the maximum allowed.
n = 0 n = 0
...@@ -1934,6 +1946,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1934,6 +1946,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
finally: finally:
del activity_tool.__class__.doSomething del activity_tool.__class__.doSomething
DB.query = original_query DB.query = original_query
Message.dump = original_dump
def test_115_TestSerializationTagSQLDictPreventsParallelExecution(self): def test_115_TestSerializationTagSQLDictPreventsParallelExecution(self):
""" """
......
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