Track locks by (dev, ino); close file handlers between tests (#34122)
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
import sys
|
||||
import tempfile
|
||||
import xml.etree.ElementTree
|
||||
from typing import Dict # novm
|
||||
|
||||
import py
|
||||
import pytest
|
||||
@@ -26,6 +25,7 @@
|
||||
import archspec.cpu.schema
|
||||
|
||||
import llnl.util.lang
|
||||
import llnl.util.lock
|
||||
import llnl.util.tty as tty
|
||||
from llnl.util.filesystem import copy_tree, mkdirp, remove_linked_tree, working_dir
|
||||
|
||||
@@ -1640,7 +1640,6 @@ def mock_clone_repo(tmpdir_factory):
|
||||
class MockBundle(object):
|
||||
has_code = False
|
||||
name = "mock-bundle"
|
||||
versions = {} # type: Dict
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -1692,6 +1691,19 @@ def mock_test_stage(mutable_config, tmpdir):
|
||||
yield tmp_stage
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def inode_cache():
|
||||
llnl.util.lock.file_tracker.purge()
|
||||
yield
|
||||
# TODO: it is a bug when the file tracker is non-empty after a test,
|
||||
# since it means a lock was not released, or the inode was not purged
|
||||
# when acquiring the lock failed. So, we could assert that here, but
|
||||
# currently there are too many issues to fix, so look for the more
|
||||
# serious issue of having a closed file descriptor in the cache.
|
||||
assert not any(f.fh.closed for f in llnl.util.lock.file_tracker._descriptors.values())
|
||||
llnl.util.lock.file_tracker.purge()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def brand_new_binary_cache():
|
||||
yield
|
||||
|
||||
@@ -687,7 +687,9 @@ def test_upgrade_read_to_write_fails_with_readonly_file(private_lock_path):
|
||||
# upgrade to write here
|
||||
with pytest.raises(lk.LockROFileError):
|
||||
lock.acquire_write()
|
||||
lk.file_tracker.release_fh(lock.path)
|
||||
|
||||
# TODO: lk.file_tracker does not release private_lock_path
|
||||
lk.file_tracker.release_by_stat(os.stat(private_lock_path))
|
||||
|
||||
|
||||
class ComplexAcquireAndRelease(object):
|
||||
@@ -1313,6 +1315,7 @@ def test_downgrade_write_okay(tmpdir):
|
||||
lock.downgrade_write_to_read()
|
||||
assert lock._reads == 1
|
||||
assert lock._writes == 0
|
||||
lock.release_read()
|
||||
|
||||
|
||||
def test_downgrade_write_fails(tmpdir):
|
||||
@@ -1323,6 +1326,7 @@ def test_downgrade_write_fails(tmpdir):
|
||||
msg = "Cannot downgrade lock from write to read on file: lockfile"
|
||||
with pytest.raises(lk.LockDowngradeError, match=msg):
|
||||
lock.downgrade_write_to_read()
|
||||
lock.release_read()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -1362,6 +1366,7 @@ def test_upgrade_read_okay(tmpdir):
|
||||
lock.upgrade_read_to_write()
|
||||
assert lock._reads == 0
|
||||
assert lock._writes == 1
|
||||
lock.release_write()
|
||||
|
||||
|
||||
def test_upgrade_read_fails(tmpdir):
|
||||
@@ -1372,3 +1377,4 @@ def test_upgrade_read_fails(tmpdir):
|
||||
msg = "Cannot upgrade lock from read to write on file: lockfile"
|
||||
with pytest.raises(lk.LockUpgradeError, match=msg):
|
||||
lock.upgrade_read_to_write()
|
||||
lock.release_write()
|
||||
|
||||
Reference in New Issue
Block a user