[test] Make coverage in test-runner tests work with multiprocessing

This replaces multiprocessing with threading in tests to make python
coverage work.

TBR=sergiyb@chromium.org

Bug: v8:6917
Change-Id: Idff763dfefa4a7fc782133d94089b3a5b00a194d
Reviewed-on: https://chromium-review.googlesource.com/844735
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50344}
This commit is contained in:
Michael Achenbach 2017-12-30 14:37:49 +01:00 committed by Commit Bot
parent 60bc8c078f
commit 5a8e1f3f1b
2 changed files with 17 additions and 3 deletions

View File

@ -8,6 +8,21 @@ from multiprocessing import Event, Process, Queue
import traceback
def setup_testing():
"""For testing only: Use threading under the hood instead of multiprocessing
to make coverage work.
"""
global Queue
global Event
global Process
del Queue
del Event
del Process
from Queue import Queue
from threading import Event
from threading import Thread as Process
class NormalResult():
def __init__(self, result):
self.result = result

View File

@ -122,14 +122,12 @@ class SystemTest(unittest.TestCase):
try:
import coverage
if int(coverage.__version__.split('.')[0]) < 4:
# First coverage 4.0 can deal with multiprocessing.
cls._cov = None
print 'Python coverage version >= 4 required.'
raise ImportError()
cls._cov = coverage.Coverage(
source=([os.path.join(TOOLS_ROOT, 'testrunner')]),
omit=['*unittest*', '*__init__.py'],
concurrency='multiprocessing',
)
cls._cov.exclude('raise NotImplementedError')
cls._cov.exclude('if __name__ == .__main__.:')
@ -145,12 +143,13 @@ class SystemTest(unittest.TestCase):
sys.path.append(TOOLS_ROOT)
global standard_runner
from testrunner import standard_runner
from testrunner.local import pool
pool.setup_testing()
@classmethod
def tearDownClass(cls):
if cls._cov:
cls._cov.stop()
cls._cov.combine()
print ''
print cls._cov.report(show_missing=True)