diff --git a/base-plone-4.3.x.cfg b/base-plone-4.3.x.cfg index 4f54da0edf5..5843863ff85 100644 --- a/base-plone-4.3.x.cfg +++ b/base-plone-4.3.x.cfg @@ -10,6 +10,12 @@ package-namespace = opengever test-egg = opengever.core[api, tests] [test] +initialization += + # Enable c.indexing during tests, but patch it to not defer operations + from opengever.testing.patch import patch_collective_indexing + patch_collective_indexing() + from collective.indexing import monkey + arguments = ['-s', '${buildout:package-namespace}', '-s', 'plonetheme', '--exit-with-status', '--auto-color', '--auto-progress', '--xml', '--package-path', '${buildout:directory}/${buildout:package-namespace}', '${buildout:package-namespace}', '--package-path', '${buildout:directory}/plonetheme', 'plonetheme'] eggs += diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index 7bb7d5f1747..ffb8c0d77c2 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -4,6 +4,7 @@ Changelog 2019.4.0 (unreleased) --------------------- +- Enable c.indexing during tests, but patch it to not defer operations. [lgraf] - Fix upgrade step that adds linguistic index for task principal. [lgraf] - Add ftw.catalogdoctor to dependencies. [deiferni] - Fix exception formatter patch when there is no plone site. [deiferni] diff --git a/opengever/testing/patch.py b/opengever/testing/patch.py index bc2fc8d6276..25273b17895 100644 --- a/opengever/testing/patch.py +++ b/opengever/testing/patch.py @@ -36,3 +36,41 @@ def __exit__(self, exc_type, exc_value, traceback): """Restore the original value to the target object's attribute. """ self.restore() + + +def patch_collective_indexing(): + """During tests, patch collective.indexing's IndexQueue so that it + doesn't defer (re)indexing to the end of the transaction, but instead + executes these operations immediately (by always processing the queue). + + This allows us to still have c.indexing active during tests, to make use + of it's pluggable IndexQueueProcessor mechanism (used to integrate Solr), + but not have the negative side effects from deferred indexing. + """ + from collective.indexing.queue import IndexQueue + from collective.indexing.queue import processQueue + + orig_index = IndexQueue.index + + def index(self, obj, attributes=None): + result = orig_index(self, obj, attributes=attributes) + processQueue() + return result + + orig_reindex = IndexQueue.reindex + + def reindex(self, obj, attributes=None): + result = orig_reindex(self, obj, attributes=attributes) + processQueue() + return result + + orig_unindex = IndexQueue.unindex + + def unindex(self, obj): + result = orig_unindex(self, obj) + processQueue() + return result + + IndexQueue.index = index + IndexQueue.reindex = reindex + IndexQueue.unindex = unindex