summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2024-09-05 14:53:29 +0200
committerGitHub <noreply@github.com>2024-09-05 14:53:29 +0200
commit02faa7b97e80f24e7f4753c9348d76fede3d80d5 (patch)
tree90cc1ae951f4fa8e3025428c2ce46662492dafb7 /lib
parentd37749cedd3ac76d6160c3d98ed42630d789cca7 (diff)
downloadspack-02faa7b97e80f24e7f4753c9348d76fede3d80d5.tar.gz
spack-02faa7b97e80f24e7f4753c9348d76fede3d80d5.tar.bz2
spack-02faa7b97e80f24e7f4753c9348d76fede3d80d5.tar.xz
spack-02faa7b97e80f24e7f4753c9348d76fede3d80d5.zip
reindex: ensure database is empty before reindex (#46199)
fixes two tests that did not clear the in-memory bits of a database before calling reindex.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/cmd/reindex.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/spack/spack/test/cmd/reindex.py b/lib/spack/spack/test/cmd/reindex.py
index 1aceeab197..6e48a3c21c 100644
--- a/lib/spack/spack/test/cmd/reindex.py
+++ b/lib/spack/spack/test/cmd/reindex.py
@@ -2,9 +2,10 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import os
+import shutil
import spack.store
+from spack.database import Database
from spack.main import SpackCommand
install = SpackCommand("install")
@@ -23,20 +24,31 @@ def test_reindex_basic(mock_packages, mock_archive, mock_fetch, install_mockery)
assert spack.store.STORE.db.query() == all_installed
-def test_reindex_db_deleted(mock_packages, mock_archive, mock_fetch, install_mockery):
+def _clear_db(tmp_path):
+ empty_db = Database(str(tmp_path))
+ with empty_db.write_transaction():
+ pass
+ shutil.rmtree(spack.store.STORE.db.database_directory)
+ shutil.copytree(empty_db.database_directory, spack.store.STORE.db.database_directory)
+ # force a re-read of the database
+ assert len(spack.store.STORE.db.query()) == 0
+
+
+def test_reindex_db_deleted(mock_packages, mock_archive, mock_fetch, install_mockery, tmp_path):
install("libelf@0.8.13")
install("libelf@0.8.12")
all_installed = spack.store.STORE.db.query()
- os.remove(spack.store.STORE.db._index_path)
+ _clear_db(tmp_path)
+
reindex()
assert spack.store.STORE.db.query() == all_installed
def test_reindex_with_deprecated_packages(
- mock_packages, mock_archive, mock_fetch, install_mockery
+ mock_packages, mock_archive, mock_fetch, install_mockery, tmp_path
):
install("libelf@0.8.13")
install("libelf@0.8.12")
@@ -46,7 +58,8 @@ def test_reindex_with_deprecated_packages(
all_installed = spack.store.STORE.db.query(installed=any)
non_deprecated = spack.store.STORE.db.query(installed=True)
- os.remove(spack.store.STORE.db._index_path)
+ _clear_db(tmp_path)
+
reindex()
assert spack.store.STORE.db.query(installed=any) == all_installed