fix lock timeouts for good this time
This commit is contained in:
parent
2532dc1dbb
commit
d76fa59b35
|
@ -20,6 +20,8 @@ import tempfile
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
|
|
||||||
|
LOCK_TIMEOUT = 60 * 60 * 3
|
||||||
|
|
||||||
get_lock_path = operator.methodcaller("joinpath", ".lock")
|
get_lock_path = operator.methodcaller("joinpath", ".lock")
|
||||||
|
|
||||||
|
|
||||||
|
@ -155,21 +157,21 @@ def cleanup_candidates(root, prefix, keep):
|
||||||
def cleanup_numbered_dir(root, prefix, keep, consider_lock_dead_if_created_before):
|
def cleanup_numbered_dir(root, prefix, keep, consider_lock_dead_if_created_before):
|
||||||
for path in cleanup_candidates(root, prefix, keep):
|
for path in cleanup_candidates(root, prefix, keep):
|
||||||
try_cleanup(path, consider_lock_dead_if_created_before)
|
try_cleanup(path, consider_lock_dead_if_created_before)
|
||||||
known_garbage = list(root.glob("garbage-*"))
|
for path in root.glob("garbage-*"):
|
||||||
for path in known_garbage:
|
|
||||||
try_cleanup(path, consider_lock_dead_if_created_before)
|
try_cleanup(path, consider_lock_dead_if_created_before)
|
||||||
|
|
||||||
|
|
||||||
def make_numbered_dir_with_cleanup(root, prefix, keep, lock_timeout):
|
def make_numbered_dir_with_cleanup(root, prefix, keep, lock_timeout):
|
||||||
|
e = None
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
try:
|
try:
|
||||||
p = make_numbered_dir(root, prefix)
|
p = make_numbered_dir(root, prefix)
|
||||||
lock_path = create_cleanup_lock(p)
|
lock_path = create_cleanup_lock(p)
|
||||||
register_cleanup_lock_removal(lock_path)
|
register_cleanup_lock_removal(lock_path)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
raise
|
pass
|
||||||
else:
|
else:
|
||||||
consider_lock_dead_if_created_before = p.stat().st_mtime + lock_timeout
|
consider_lock_dead_if_created_before = p.stat().st_mtime - lock_timeout
|
||||||
cleanup_numbered_dir(
|
cleanup_numbered_dir(
|
||||||
root=root,
|
root=root,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
|
@ -177,6 +179,8 @@ def make_numbered_dir_with_cleanup(root, prefix, keep, lock_timeout):
|
||||||
consider_lock_dead_if_created_before=consider_lock_dead_if_created_before,
|
consider_lock_dead_if_created_before=consider_lock_dead_if_created_before,
|
||||||
)
|
)
|
||||||
return p
|
return p
|
||||||
|
assert e is not None
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
|
|
|
@ -239,7 +239,10 @@ class TestNumberedDir(object):
|
||||||
from _pytest.tmpdir import cleanup_numbered_dir
|
from _pytest.tmpdir import cleanup_numbered_dir
|
||||||
|
|
||||||
cleanup_numbered_dir(
|
cleanup_numbered_dir(
|
||||||
root=tmp_path, prefix=self.PREFIX, keep=2, consider_lock_dead_after=0
|
root=tmp_path,
|
||||||
|
prefix=self.PREFIX,
|
||||||
|
keep=2,
|
||||||
|
consider_lock_dead_if_created_before=0,
|
||||||
)
|
)
|
||||||
a, b = tmp_path.iterdir()
|
a, b = tmp_path.iterdir()
|
||||||
print(a, b)
|
print(a, b)
|
||||||
|
@ -251,5 +254,10 @@ class TestNumberedDir(object):
|
||||||
p = tmpdir.make_numbered_dir(root=tmp_path, prefix=self.PREFIX)
|
p = tmpdir.make_numbered_dir(root=tmp_path, prefix=self.PREFIX)
|
||||||
|
|
||||||
tmpdir.create_cleanup_lock(p)
|
tmpdir.create_cleanup_lock(p)
|
||||||
assert not tmpdir.ensure_deletable(p, p.stat().st_mtime + 1)
|
|
||||||
assert tmpdir.ensure_deletable(p, p.stat().st_mtime - 1)
|
assert not tmpdir.ensure_deletable(
|
||||||
|
p, consider_lock_dead_if_created_before=p.stat().st_mtime - 1
|
||||||
|
)
|
||||||
|
assert tmpdir.ensure_deletable(
|
||||||
|
p, consider_lock_dead_if_created_before=p.stat().st_mtime + 1
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue