-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When running experiments on slurm, it can happen that multiple nodes fetch the feature model repository at the same time. As nodes may use a shared feature model repository (E.g. on /scratch/) this can lead to issues. This is no issue if the feature model repository is already up-to-date, however if there are any upstream changes this leads to errors in the fetch on some nodes and subsequent failure of the slurm jobs. --------- Co-authored-by: Lukas Abelt <[email protected]> Co-authored-by: Florian Sattler <[email protected]>
- Loading branch information
1 parent
cecda8b
commit 62cbd3a
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Test the filesystem utils of VaRA-TS.""" | ||
import errno | ||
import os | ||
import unittest | ||
import uuid | ||
from fcntl import flock, LOCK_EX, LOCK_NB, LOCK_UN | ||
|
||
from varats.utils.filesystem_util import lock_file | ||
|
||
|
||
class TestFileLock(unittest.TestCase): | ||
"""Tests whether the lock context manager works correctly.""" | ||
|
||
def test_file_locking(self): | ||
"""Test that the file is locked when in a context manager.""" | ||
tmp_lock_file = "/tmp/lock-test.lock" | ||
|
||
with lock_file(tmp_lock_file): | ||
# File should automatically be created | ||
self.assertTrue(os.path.exists(tmp_lock_file)) | ||
|
||
f = os.open(tmp_lock_file, os.O_RDONLY) | ||
|
||
with self.assertRaises(OSError) as context: | ||
# A non-blocking attempt to lock the file again should fail immediately | ||
flock(f, LOCK_EX | LOCK_NB) | ||
os.close(f) | ||
self.assertEqual(context.exception.errno, errno.EWOULDBLOCK) | ||
|
||
# Attempting to lock the file and immediately unlocking should now work | ||
f = os.open(tmp_lock_file, os.O_RDONLY) | ||
flock(f, LOCK_EX | LOCK_NB) | ||
flock(f, LOCK_UN) | ||
os.close(f) | ||
|
||
def test_lock_file_new_folder(self): | ||
"""Test that the lock context manager works correctly when the lock file | ||
is in a new folder.""" | ||
tmp_lock_file = f"/tmp/{uuid.uuid4()}" | ||
|
||
while os.path.isdir(tmp_lock_file): | ||
tmp_lock_file = f"/tmp/{uuid.uuid4()}" | ||
|
||
tmp_lock_file += "/lock-test.lock" | ||
|
||
with lock_file(tmp_lock_file): | ||
# File should automatically be created | ||
self.assertTrue(os.path.exists(tmp_lock_file)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters