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.
This commit is contained in:
parent
d37749cedd
commit
02faa7b97e
@ -2,9 +2,10 @@
|
|||||||
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
import os
|
import shutil
|
||||||
|
|
||||||
import spack.store
|
import spack.store
|
||||||
|
from spack.database import Database
|
||||||
from spack.main import SpackCommand
|
from spack.main import SpackCommand
|
||||||
|
|
||||||
install = SpackCommand("install")
|
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
|
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.13")
|
||||||
install("libelf@0.8.12")
|
install("libelf@0.8.12")
|
||||||
|
|
||||||
all_installed = spack.store.STORE.db.query()
|
all_installed = spack.store.STORE.db.query()
|
||||||
|
|
||||||
os.remove(spack.store.STORE.db._index_path)
|
_clear_db(tmp_path)
|
||||||
|
|
||||||
reindex()
|
reindex()
|
||||||
|
|
||||||
assert spack.store.STORE.db.query() == all_installed
|
assert spack.store.STORE.db.query() == all_installed
|
||||||
|
|
||||||
|
|
||||||
def test_reindex_with_deprecated_packages(
|
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.13")
|
||||||
install("libelf@0.8.12")
|
install("libelf@0.8.12")
|
||||||
@ -46,7 +58,8 @@ def test_reindex_with_deprecated_packages(
|
|||||||
all_installed = spack.store.STORE.db.query(installed=any)
|
all_installed = spack.store.STORE.db.query(installed=any)
|
||||||
non_deprecated = spack.store.STORE.db.query(installed=True)
|
non_deprecated = spack.store.STORE.db.query(installed=True)
|
||||||
|
|
||||||
os.remove(spack.store.STORE.db._index_path)
|
_clear_db(tmp_path)
|
||||||
|
|
||||||
reindex()
|
reindex()
|
||||||
|
|
||||||
assert spack.store.STORE.db.query(installed=any) == all_installed
|
assert spack.store.STORE.db.query(installed=any) == all_installed
|
||||||
|
Loading…
Reference in New Issue
Block a user