fix and test issue with copying by reference vs value

This commit is contained in:
Gregory Becker 2023-05-25 01:43:55 +02:00
parent b9cf63aa41
commit 2d46de5741
2 changed files with 17 additions and 6 deletions

View File

@ -1346,8 +1346,8 @@ def concretize(self, force=False, tests=False):
the user spec and the corresponding concretized spec. the user spec and the corresponding concretized spec.
""" """
old_concretized_user_specs = self.concretized_user_specs[:] old_concretized_user_specs = self.concretized_user_specs[:]
old_concretized_order = self.concretized_order old_concretized_order = self.concretized_order[:]
old_specs_by_hash = self.specs_by_hash old_specs_by_hash = self.specs_by_hash.copy()
try: try:
if force: if force:

View File

@ -2766,6 +2766,11 @@ def test_virtual_spec_concretize_together(tmpdir):
[ [
(True, (spack.concretize, "concretize_specs_together")), (True, (spack.concretize, "concretize_specs_together")),
("when_possible", (spack.solver.asp.Solver, "solve_in_rounds")), ("when_possible", (spack.solver.asp.Solver, "solve_in_rounds")),
# An earlier failure so that we test the case where the internal state
# has been changed, but the pointer to the internal variables has not change.
# This effectively tests that we are properly copying by value not by
# reference for the transactional concretization
(True, (spack.environment.Environment, "_get_specs_to_concretize")),
], ],
) )
def test_concretize_transactional(unify, method_to_fail, monkeypatch): def test_concretize_transactional(unify, method_to_fail, monkeypatch):
@ -2773,20 +2778,26 @@ def test_concretize_transactional(unify, method_to_fail, monkeypatch):
e.unify = unify e.unify = unify
e.add("mpi") e.add("mpi")
e.add("zlib")
e.concretize() e.concretize()
# remove one spec and add another to ensure we test with changes before
# and after the environment is cleared during concretization
e.remove("zlib")
e.add("libelf")
def fail(*args, **kwargs): def fail(*args, **kwargs):
raise Exception("Test failures") raise Exception("Test failures")
location, method = method_to_fail location, method = method_to_fail
monkeypatch.setattr(location, method, fail) monkeypatch.setattr(location, method, fail)
first_user_specs = e.concretized_user_specs first_user_specs = e.concretized_user_specs[:]
first_order = e.concretized_order first_order = e.concretized_order[:]
first_hash_dict = e.specs_by_hash first_hash_dict = e.specs_by_hash.copy()
try: try:
e.concretize(force=True) e.concretize()
except Exception: except Exception:
pass pass