Fix running of worker process in test suite

This commit is contained in:
Kovid Goyal 2017-05-03 16:22:27 +05:30
parent e8371dc78a
commit 55844a8b8e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -7,12 +7,12 @@ from __future__ import absolute_import, division, print_function, unicode_litera
import os import os
import shutil import shutil
import subprocess import subprocess
import sys
import tempfile import tempfile
import unittest import unittest
from threading import Thread from threading import Thread
from calibre.constants import iswindows, fcntl from calibre.constants import fcntl, iswindows
from calibre.debug import run_calibre_debug
from calibre.utils.lock import ExclusiveFile, unix_open from calibre.utils.lock import ExclusiveFile, unix_open
@ -32,6 +32,17 @@ class Other(Thread):
self.locked = False self.locked = False
def run_worker(mod, func, **kw):
exe = [sys.executable, os.path.join(sys.setup_dir, 'run-calibre-worker.py')]
env = kw.get('env', os.environ.copy())
env['CALIBRE_SIMPLE_WORKER'] = mod + ':' + func
if iswindows:
import win32process
kw['creationflags'] = win32process.CREATE_NO_WINDOW
kw['env'] = env
return subprocess.Popen(exe, **kw)
class IPCLockTest(unittest.TestCase): class IPCLockTest(unittest.TestCase):
def setUp(self): def setUp(self):
@ -57,11 +68,7 @@ class IPCLockTest(unittest.TestCase):
) )
def test_exclusive_file_other_process(self): def test_exclusive_file_other_process(self):
child = run_calibre_debug( child = run_worker('calibre.utils.test_lock', 'other1', stdout=subprocess.PIPE)
'-c',
'from calibre.utils.test_lock import other1; other1()',
stdout=subprocess.PIPE
)
ready = child.stdout.readline() ready = child.stdout.readline()
self.assertEqual(ready.strip(), b'ready') self.assertEqual(ready.strip(), b'ready')
ef = FastFailEF('test') ef = FastFailEF('test')