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
|
||||
# On Unix this is done by the subprocess module
|
||||
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
|
||||
# launch the last run process from the bundle
|
||||
# so launch the gui as usual
|
||||
|
@ -27,14 +27,17 @@ class Other(Thread):
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
with FastFailEF('test'):
|
||||
with FastFailEF('testsp'):
|
||||
self.locked = True
|
||||
except EnvironmentError:
|
||||
self.locked = False
|
||||
|
||||
|
||||
def run_worker(mod, func, **kw):
|
||||
exe = [sys.executable, os.path.join(sys.setup_dir, 'run-calibre-worker.py')]
|
||||
try:
|
||||
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['CALIBRE_SIMPLE_WORKER'] = mod + ':' + func
|
||||
if iswindows:
|
||||
@ -56,41 +59,53 @@ class IPCLockTest(unittest.TestCase):
|
||||
shutil.rmtree(self.tdir)
|
||||
|
||||
def test_exclusive_file_same_process(self):
|
||||
with ExclusiveFile('test'):
|
||||
ef = FastFailEF('test')
|
||||
fname = 'testsp'
|
||||
with ExclusiveFile(fname):
|
||||
ef = FastFailEF(fname)
|
||||
self.assertRaises(EnvironmentError, ef.__enter__)
|
||||
t = Other()
|
||||
t.start(), t.join()
|
||||
self.assertIs(t.locked, False)
|
||||
if not iswindows:
|
||||
with unix_open('test') as f:
|
||||
with unix_open(fname) as f:
|
||||
self.assertEqual(
|
||||
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')
|
||||
print(1111111, sys.executable, sys.setup_dir, child)
|
||||
while child.poll() is None:
|
||||
if os.path.exists('ready'):
|
||||
break
|
||||
time.sleep(0.01)
|
||||
self.assertIsNone(child.poll(), 'child died without creating ready dir')
|
||||
ef = FastFailEF('test')
|
||||
self.assertRaises(EnvironmentError, ef.__enter__)
|
||||
child.kill()
|
||||
self.assertIsNotNone(child.wait())
|
||||
with ExclusiveFile('test'):
|
||||
pass
|
||||
try:
|
||||
while child.poll() is None:
|
||||
if os.path.exists('ready'):
|
||||
break
|
||||
time.sleep(0.01)
|
||||
self.assertIsNone(child.poll(), 'child died without creating ready dir')
|
||||
ef = FastFailEF('test')
|
||||
self.assertRaises(EnvironmentError, ef.__enter__)
|
||||
if clean_exit:
|
||||
os.mkdir('quit')
|
||||
else:
|
||||
child.kill()
|
||||
self.assertIsNotNone(child.wait())
|
||||
with ExclusiveFile('test', timeout=3):
|
||||
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():
|
||||
print('in other')
|
||||
e = ExclusiveFile('test')
|
||||
with e:
|
||||
os.mkdir('ready')
|
||||
print(22222222)
|
||||
time.sleep(30)
|
||||
while not os.path.exists('quit'):
|
||||
time.sleep(0.02)
|
||||
|
||||
|
||||
def find_tests():
|
||||
|
Loading…
x
Reference in New Issue
Block a user