[FIX] core: add test on pre/post-commit callbacks

This test ensures that method `Callbacks.run` is re-entrant, i.e., it
can be called from a callback being run.  The behavior is to execute the
remaining callbacks, and then resume the current one.

This completes https://github.com/odoo/odoo/pull/57469.

closes odoo/odoo#57778

X-original-commit: 7de434ebc091c4d85615c6cf69240e07b98fe767
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
Raphael Collet
2020-09-15 16:52:09 +00:00
parent c500bb0484
commit 7ab3443bc5
+22
View File
@@ -321,6 +321,28 @@ class TestCallbacks(BaseCase):
callbacks.run()
self.assertEqual(log, [[1, 2, 3]])
def test_reentrant(self):
log = []
callbacks = misc.Callbacks()
# register foo that runs callbacks
@callbacks.add
def foo():
log.append("foo1")
callbacks.run()
log.append("foo2")
@callbacks.add
def bar():
log.append("bar")
# both foo() and bar() are called once
callbacks.run()
self.assertEqual(log, ["foo1", "bar", "foo2"])
callbacks.run()
self.assertEqual(log, ["foo1", "bar", "foo2"])
class TestRemoveAccents(BaseCase):
def test_empty_string(self):