From 71b027bcdf729fba01b9eacd88bfc83028a56bfa Mon Sep 17 00:00:00 2001 From: UlrichB22 <97119703+UlrichB22@users.noreply.github.com> Date: Tue, 9 Apr 2024 23:06:39 +0200 Subject: [PATCH] WIP: fix open files issue with whoosh-reloaded and test_index_update --- pyproject.toml | 2 +- src/moin/conftest.py | 10 ++++++---- src/moin/storage/middleware/indexing.py | 3 +-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 260381a32..a284e1bdf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ dependencies = [ "markupsafe <= 2.2.0", # safe html and xml "pygments >= 1.4", # src code / text file highlighting "Werkzeug >= 3.0.0", # WSGI toolkit - "whoosh >= 2.7.0", # needed for indexed search + "whoosh-reloaded >= 2.7.5", # needed for indexed search "pdfminer.six", # pdf -> text/plain conversion "passlib >= 1.6.0", # strong password hashing (1.6 needed for consteq) "sqlalchemy < 2.0", # used by sqla store diff --git a/src/moin/conftest.py b/src/moin/conftest.py index 23909a6b7..8c72437de 100644 --- a/src/moin/conftest.py +++ b/src/moin/conftest.py @@ -2,6 +2,7 @@ # Copyright: 2007 MoinMoin:AlexanderSchremmer # Copyright: 2008,2011 MoinMoin:ThomasWaldmann # Copyright: 2023 MoinMoin project +# Copyright: 2024 MoinMoin:UlrichB # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. """ @@ -16,6 +17,7 @@ use a Config class to define the required configuration within the test class. """ +import gc import pytest import py @@ -64,11 +66,11 @@ def app_ctx(cfg): teardown_wiki("") ctx.pop() try: - # simulate ERROR PermissionError: - # [WinError 32] The process cannot access the file because it is being used by another process - assert [] == get_open_wiki_files() - finally: destroy_app(app) + except PermissionError: # [WinError 32] ... the file is being used by another process + gc.collect() # triggers close of index files + destroy_app(app) + assert len(get_open_wiki_files()) < 1 @pytest.fixture(autouse=True) diff --git a/src/moin/storage/middleware/indexing.py b/src/moin/storage/middleware/indexing.py index 431ec6daf..552491f44 100644 --- a/src/moin/storage/middleware/indexing.py +++ b/src/moin/storage/middleware/indexing.py @@ -1,6 +1,7 @@ # Copyright: 2011 MoinMoin:RonnyPfannschmidt # Copyright: 2011 MoinMoin:ThomasWaldmann # Copyright: 2011 MoinMoin:MichaelMayorov +# Copyright: 2024 MoinMoin:UlrichB # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. """ @@ -48,7 +49,6 @@ usually it is even just the small and thus quick latest-revs index. """ -import gc import os import sys import shutil @@ -1287,7 +1287,6 @@ def store_revision( backend_name, revid = backend.store(meta, data) meta[REVID] = revid self.indexer.index_revision(meta, content, backend_name, force_latest=not overwrite) - gc.collect() # triggers close of index files from is_latest search if not overwrite: self._current = get_indexer(self.indexer._document, revid=revid) if return_rev: