[svn r63000] * do an as lightweight config.mktemp() as possible
* avoid writing lock files if lock_timeout is 0 or None --HG-- branch : trunk
This commit is contained in:
parent
47a91d2aa9
commit
4aac96fa13
|
@ -618,25 +618,26 @@ class LocalPath(common.FSPathBase, PlatformMixin):
|
||||||
|
|
||||||
# put a .lock file in the new directory that will be removed at
|
# put a .lock file in the new directory that will be removed at
|
||||||
# process exit
|
# process exit
|
||||||
lockfile = udir.join('.lock')
|
if lock_timeout:
|
||||||
mypid = os.getpid()
|
lockfile = udir.join('.lock')
|
||||||
if hasattr(lockfile, 'mksymlinkto'):
|
mypid = os.getpid()
|
||||||
lockfile.mksymlinkto(str(mypid))
|
if hasattr(lockfile, 'mksymlinkto'):
|
||||||
else:
|
lockfile.mksymlinkto(str(mypid))
|
||||||
lockfile.write(str(mypid))
|
else:
|
||||||
def try_remove_lockfile():
|
lockfile.write(str(mypid))
|
||||||
# in a fork() situation, only the last process should
|
def try_remove_lockfile():
|
||||||
# remove the .lock, otherwise the other processes run the
|
# in a fork() situation, only the last process should
|
||||||
# risk of seeing their temporary dir disappear. For now
|
# remove the .lock, otherwise the other processes run the
|
||||||
# we remove the .lock in the parent only (i.e. we assume
|
# risk of seeing their temporary dir disappear. For now
|
||||||
# that the children finish before the parent).
|
# we remove the .lock in the parent only (i.e. we assume
|
||||||
if os.getpid() != mypid:
|
# that the children finish before the parent).
|
||||||
return
|
if os.getpid() != mypid:
|
||||||
try:
|
return
|
||||||
lockfile.remove()
|
try:
|
||||||
except py.error.Error:
|
lockfile.remove()
|
||||||
pass
|
except py.error.Error:
|
||||||
atexit.register(try_remove_lockfile)
|
pass
|
||||||
|
atexit.register(try_remove_lockfile)
|
||||||
|
|
||||||
# prune old directories
|
# prune old directories
|
||||||
if keep:
|
if keep:
|
||||||
|
@ -647,7 +648,7 @@ class LocalPath(common.FSPathBase, PlatformMixin):
|
||||||
try:
|
try:
|
||||||
t1 = lf.lstat().mtime
|
t1 = lf.lstat().mtime
|
||||||
t2 = lockfile.lstat().mtime
|
t2 = lockfile.lstat().mtime
|
||||||
if abs(t2-t1) < lock_timeout:
|
if not lock_timeout or abs(t2-t1) < lock_timeout:
|
||||||
continue # skip directories still locked
|
continue # skip directories still locked
|
||||||
except py.error.Error:
|
except py.error.Error:
|
||||||
pass # assume that it means that there is no 'lf'
|
pass # assume that it means that there is no 'lf'
|
||||||
|
|
|
@ -275,8 +275,6 @@ class TestExecution(LocalSetup):
|
||||||
assert not numdir.new(ext=str(i-3)).check()
|
assert not numdir.new(ext=str(i-3)).check()
|
||||||
|
|
||||||
def test_locked_make_numbered_dir(self):
|
def test_locked_make_numbered_dir(self):
|
||||||
if py.test.config.option.boxed:
|
|
||||||
py.test.skip("Fails when run as boxed tests")
|
|
||||||
root = self.tmpdir
|
root = self.tmpdir
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
numdir = local.make_numbered_dir(prefix='base2.', rootdir=root,
|
numdir = local.make_numbered_dir(prefix='base2.', rootdir=root,
|
||||||
|
|
|
@ -140,7 +140,7 @@ class Config(object):
|
||||||
return basetemp.mkdir(basename)
|
return basetemp.mkdir(basename)
|
||||||
else:
|
else:
|
||||||
return py.path.local.make_numbered_dir(prefix=basename + "-",
|
return py.path.local.make_numbered_dir(prefix=basename + "-",
|
||||||
keep=0, rootdir=basetemp)
|
keep=0, rootdir=basetemp, lock_timeout=None)
|
||||||
|
|
||||||
def getcolitems(self):
|
def getcolitems(self):
|
||||||
return [self.getfsnode(arg) for arg in self.args]
|
return [self.getfsnode(arg) for arg in self.args]
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
|
|
||||||
""" Tests various aspects of dist, like ssh hosts setup/teardown
|
|
||||||
"""
|
|
||||||
|
|
||||||
import py
|
import py
|
||||||
from py.__.test.dsession.dsession import DSession
|
from py.__.test.dsession.dsession import DSession
|
||||||
from test_masterslave import EventQueue
|
from test_masterslave import EventQueue
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
class TestAsyncFunctional:
|
class TestAsyncFunctional:
|
||||||
def test_conftest_options(self, testdir):
|
def test_conftest_options(self, testdir):
|
||||||
|
@ -80,6 +74,7 @@ class TestAsyncFunctional:
|
||||||
|
|
||||||
def test_nice_level(self, testdir):
|
def test_nice_level(self, testdir):
|
||||||
""" Tests if nice level behaviour is ok """
|
""" Tests if nice level behaviour is ok """
|
||||||
|
import os
|
||||||
if not hasattr(os, 'nice'):
|
if not hasattr(os, 'nice'):
|
||||||
py.test.skip("no os.nice() available")
|
py.test.skip("no os.nice() available")
|
||||||
testdir.makepyfile(conftest="""
|
testdir.makepyfile(conftest="""
|
||||||
|
|
Loading…
Reference in New Issue