From 031ea4d35191c2fa69dd74e04a25524b6248aee9 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Fri, 12 May 2023 11:40:41 +0000 Subject: [PATCH] [FIX] tests, registry: reset_changes in httpcase When inside an HttpCase, the end of a successful request will `signal_changes` meaning that the registry_invalidated flag is removed. A second issue is that this flag is thread local meaning that if a request set the flag, it won't be visible from the test thread. For those reasons, this commit ensures the registry sequences are incremented as in production mode, and adds a check that the sequence didn't change during the tests, calling `setup_models` the registry manually if needed. closes odoo/odoo#121268 Signed-off-by: Christophe Monniez (moc) --- odoo/modules/registry.py | 13 +++++++++++-- odoo/tests/common.py | 10 ++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/odoo/modules/registry.py b/odoo/modules/registry.py index 9f74c010797..f56504ce93b 100644 --- a/odoo/modules/registry.py +++ b/odoo/modules/registry.py @@ -783,7 +783,16 @@ class Registry(Mapping): def signal_changes(self): """ Notifies other processes if registry or cache has been invalidated. """ - if self.registry_invalidated and not self.in_test_mode(): + if self.in_test_mode(): + if self.registry_invalidated: + self.registry_sequence += 1 + if self.cache_invalidated: + self.cache_sequence += 1 + self.registry_invalidated = False + self.cache_invalidated = False + return + + if self.registry_invalidated: _logger.info("Registry changed, signaling through the database") with closing(self.cursor()) as cr: cr.execute("select nextval('base_registry_signaling')") @@ -791,7 +800,7 @@ class Registry(Mapping): # no need to notify cache invalidation in case of registry invalidation, # because reloading the registry implies starting with an empty cache - elif self.cache_invalidated and not self.in_test_mode(): + elif self.cache_invalidated: _logger.info("At least one model cache has been invalidated, signaling through the database.") with closing(self.cursor()) as cr: cr.execute("select nextval('base_cache_signaling')") diff --git a/odoo/tests/common.py b/odoo/tests/common.py index 01af7e5971f..c086479b349 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -712,9 +712,15 @@ class TransactionCase(BaseCase): super().setUpClass() cls.addClassCleanup(cls._gc_filestore) - cls.registry = odoo.registry(get_db_name()) - cls.addClassCleanup(cls.registry.reset_changes) + cls.registry_start_sequence = cls.registry.registry_sequence + def reset_changes(): + if (cls.registry_start_sequence != cls.registry.registry_sequence) or cls.registry.registry_invalidated: + with cls.registry.cursor() as cr: + cls.registry.setup_models(cr) + cls.registry.registry_invalidated = False + + cls.addClassCleanup(reset_changes) cls.addClassCleanup(cls.registry.clear_caches) cls.cr = cls.registry.cursor()