Skip to content

Commit

Permalink
Merge pull request #3889 from boegel/fix_remove_lock
Browse files Browse the repository at this point in the history
only remove lock if it was created in the same EasyBuild session (not if it existed already)
  • Loading branch information
branfosj authored Nov 11, 2021
2 parents 7333b4b + 4baee22 commit 450d7bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3823,6 +3823,7 @@ def run_all_steps(self, run_test_cases):

ignore_locks = build_option('ignore_locks')

lock_created = False
try:
if ignore_locks:
self.log.info("Ignoring locks...")
Expand All @@ -3835,6 +3836,7 @@ def run_all_steps(self, run_test_cases):

# create lock to avoid that another installation running in parallel messes things up
create_lock(lock_name)
lock_created = True

for step_name, descr, step_methods, skippable in steps:
if self.skip_step(step_name, skippable):
Expand Down Expand Up @@ -3864,7 +3866,8 @@ def run_all_steps(self, run_test_cases):
except StopException:
pass
finally:
if not ignore_locks:
# remove lock, but only if it was created in this session (not if it was there already)
if lock_created:
remove_lock(lock_name)

stop_progress_bar(PROGRESS_BAR_EASYCONFIG)
Expand Down
15 changes: 11 additions & 4 deletions test/framework/toy_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3251,6 +3251,13 @@ def test_toy_build_lock(self):
error_pattern = "Lock .*_software_toy_0.0.lock already exists, aborting!"
self.assertErrorRegex(EasyBuildError, error_pattern, self.test_toy_build, raise_error=True, verbose=False)

# lock should still be there after it was hit
self.assertTrue(os.path.exists(toy_lock_path))

# trying again should give same result
self.assertErrorRegex(EasyBuildError, error_pattern, self.test_toy_build, raise_error=True, verbose=False)
self.assertTrue(os.path.exists(toy_lock_path))

locks_dir = os.path.join(self.test_prefix, 'locks')

# no lock in place, so installation proceeds as normal
Expand All @@ -3269,7 +3276,7 @@ def test_toy_build_lock(self):
orig_sigalrm_handler = signal.getsignal(signal.SIGALRM)

# define a context manager that remove a lock after a while, so we can check the use of --wait-for-lock
class remove_lock_after(object):
class RemoveLockAfter(object):
def __init__(self, seconds, lock_fp):
self.seconds = seconds
self.lock_fp = lock_fp
Expand Down Expand Up @@ -3317,7 +3324,7 @@ def __exit__(self, type, value, traceback):
all_args = extra_args + opts

# use context manager to remove lock after 3 seconds
with remove_lock_after(3, toy_lock_path):
with RemoveLockAfter(3, toy_lock_path):
self.mock_stderr(True)
self.mock_stdout(True)
self.test_toy_build(extra_args=all_args, verify=False, raise_error=True, testing=False)
Expand Down Expand Up @@ -3385,7 +3392,7 @@ def test_toy_lock_cleanup_signals(self):
orig_sigalrm_handler = signal.getsignal(signal.SIGALRM)

# context manager which stops the function being called with the specified signal
class wait_and_signal(object):
class WaitAndSignal(object):
def __init__(self, seconds, signum):
self.seconds = seconds
self.signum = signum
Expand Down Expand Up @@ -3420,7 +3427,7 @@ def __exit__(self, type, value, traceback):
# avoid recycling stderr of previous test
stderr = ''

with wait_and_signal(1, signum):
with WaitAndSignal(1, signum):

# change back to original working directory before each test
change_dir(orig_wd)
Expand Down

0 comments on commit 450d7bb

Please sign in to comment.