mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
test_lock now passes on my OS X machine
This commit is contained in:
parent
ba21c51e97
commit
e65966962e
@ -158,7 +158,7 @@ def main():
|
|||||||
# Close open file descriptors inherited from parent
|
# Close open file descriptors inherited from parent
|
||||||
# On Unix this is done by the subprocess module
|
# On Unix this is done by the subprocess module
|
||||||
os.closerange(3, 256)
|
os.closerange(3, 256)
|
||||||
if isosx and 'CALIBRE_WORKER_ADDRESS' not in os.environ and '--pipe-worker' not in sys.argv:
|
if isosx and 'CALIBRE_WORKER_ADDRESS' not in os.environ and 'CALIBRE_SIMPLE_WORKER' not in os.environ and '--pipe-worker' not in sys.argv:
|
||||||
# On some OS X computers launchd apparently tries to
|
# On some OS X computers launchd apparently tries to
|
||||||
# launch the last run process from the bundle
|
# launch the last run process from the bundle
|
||||||
# so launch the gui as usual
|
# so launch the gui as usual
|
||||||
|
@ -27,14 +27,17 @@ class Other(Thread):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
with FastFailEF('test'):
|
with FastFailEF('testsp'):
|
||||||
self.locked = True
|
self.locked = True
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
self.locked = False
|
self.locked = False
|
||||||
|
|
||||||
|
|
||||||
def run_worker(mod, func, **kw):
|
def run_worker(mod, func, **kw):
|
||||||
|
try:
|
||||||
exe = [sys.executable, os.path.join(sys.setup_dir, 'run-calibre-worker.py')]
|
exe = [sys.executable, os.path.join(sys.setup_dir, 'run-calibre-worker.py')]
|
||||||
|
except AttributeError:
|
||||||
|
exe = [os.path.join(os.path.dirname(os.path.abspath(sys.executable)), 'calibre-parallel' + ('.exe' if iswindows else ''))]
|
||||||
env = kw.get('env', os.environ.copy())
|
env = kw.get('env', os.environ.copy())
|
||||||
env['CALIBRE_SIMPLE_WORKER'] = mod + ':' + func
|
env['CALIBRE_SIMPLE_WORKER'] = mod + ':' + func
|
||||||
if iswindows:
|
if iswindows:
|
||||||
@ -56,21 +59,22 @@ class IPCLockTest(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tdir)
|
shutil.rmtree(self.tdir)
|
||||||
|
|
||||||
def test_exclusive_file_same_process(self):
|
def test_exclusive_file_same_process(self):
|
||||||
with ExclusiveFile('test'):
|
fname = 'testsp'
|
||||||
ef = FastFailEF('test')
|
with ExclusiveFile(fname):
|
||||||
|
ef = FastFailEF(fname)
|
||||||
self.assertRaises(EnvironmentError, ef.__enter__)
|
self.assertRaises(EnvironmentError, ef.__enter__)
|
||||||
t = Other()
|
t = Other()
|
||||||
t.start(), t.join()
|
t.start(), t.join()
|
||||||
self.assertIs(t.locked, False)
|
self.assertIs(t.locked, False)
|
||||||
if not iswindows:
|
if not iswindows:
|
||||||
with unix_open('test') as f:
|
with unix_open(fname) as f:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
1, fcntl.fcntl(f.fileno(), fcntl.F_GETFD) & fcntl.FD_CLOEXEC
|
1, fcntl.fcntl(f.fileno(), fcntl.F_GETFD) & fcntl.FD_CLOEXEC
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_exclusive_file_other_process(self):
|
def run_other_ef_op(self, clean_exit):
|
||||||
child = run_worker('calibre.utils.test_lock', 'other1')
|
child = run_worker('calibre.utils.test_lock', 'other1')
|
||||||
print(1111111, sys.executable, sys.setup_dir, child)
|
try:
|
||||||
while child.poll() is None:
|
while child.poll() is None:
|
||||||
if os.path.exists('ready'):
|
if os.path.exists('ready'):
|
||||||
break
|
break
|
||||||
@ -78,19 +82,30 @@ class IPCLockTest(unittest.TestCase):
|
|||||||
self.assertIsNone(child.poll(), 'child died without creating ready dir')
|
self.assertIsNone(child.poll(), 'child died without creating ready dir')
|
||||||
ef = FastFailEF('test')
|
ef = FastFailEF('test')
|
||||||
self.assertRaises(EnvironmentError, ef.__enter__)
|
self.assertRaises(EnvironmentError, ef.__enter__)
|
||||||
|
if clean_exit:
|
||||||
|
os.mkdir('quit')
|
||||||
|
else:
|
||||||
child.kill()
|
child.kill()
|
||||||
self.assertIsNotNone(child.wait())
|
self.assertIsNotNone(child.wait())
|
||||||
with ExclusiveFile('test'):
|
with ExclusiveFile('test', timeout=3):
|
||||||
pass
|
pass
|
||||||
|
finally:
|
||||||
|
if child.poll() is None:
|
||||||
|
child.kill()
|
||||||
|
|
||||||
|
def test_exclusive_file_other_process_clean(self):
|
||||||
|
self.run_other_ef_op(True)
|
||||||
|
|
||||||
|
def test_exclusive_file_other_process_kill(self):
|
||||||
|
self.run_other_ef_op(False)
|
||||||
|
|
||||||
|
|
||||||
def other1():
|
def other1():
|
||||||
print('in other')
|
|
||||||
e = ExclusiveFile('test')
|
e = ExclusiveFile('test')
|
||||||
with e:
|
with e:
|
||||||
os.mkdir('ready')
|
os.mkdir('ready')
|
||||||
print(22222222)
|
while not os.path.exists('quit'):
|
||||||
time.sleep(30)
|
time.sleep(0.02)
|
||||||
|
|
||||||
|
|
||||||
def find_tests():
|
def find_tests():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user