Skip to content

Commit

Permalink
test: support mixed parallel/sequential tests
Browse files Browse the repository at this point in the history
Support mixed parallel/sequential tests. Merge the `io` and `simple
message` test runs together in a Makefile
  • Loading branch information
indutny committed Dec 16, 2014
1 parent 3c66b19 commit 682eb7e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ distclean:
-rm -rf node_modules

test: all
$(PYTHON) tools/test.py --mode=release simple message -j9
$(PYTHON) tools/test.py --mode=release io
$(PYTHON) tools/test.py --mode=release simple message io -j9
$(MAKE) jslint
$(MAKE) cpplint

Expand Down
2 changes: 1 addition & 1 deletion test/simple/testcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
import testpy

def GetConfiguration(context, root):
return testpy.SimpleTestConfiguration(context, root, 'simple')
return testpy.ParallelTestConfiguration(context, root, 'simple')
13 changes: 12 additions & 1 deletion test/testpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def GetCommand(self):
def GetSource(self):
return open(self.file).read()


class SimpleTestConfiguration(test.TestConfiguration):

def __init__(self, context, root, section, additional=[]):
Expand Down Expand Up @@ -136,6 +135,18 @@ def GetTestStatus(self, sections, defs):
if exists(status_file):
test.ReadConfigurationInto(status_file, sections, defs)

class ParallelTestConfiguration(SimpleTestConfiguration):
def __init__(self, context, root, section, additional=[]):
super(ParallelTestConfiguration, self).__init__(context, root, section,
additional)

def ListTests(self, current_path, path, arch, mode):
result = super(ParallelTestConfiguration, self).ListTests(
current_path, path, arch, mode)
for test in result:
test.parallel = True
return result

class AddonTestConfiguration(SimpleTestConfiguration):
def __init__(self, context, root, section, additional=[]):
super(AddonTestConfiguration, self).__init__(context, root, section)
Expand Down
27 changes: 20 additions & 7 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ class ProgressIndicator(object):
def __init__(self, cases, flaky_tests_mode):
self.cases = cases
self.flaky_tests_mode = flaky_tests_mode
self.queue = Queue(len(cases))
self.queue = {
'parallel': Queue(len(cases)),
'sequential': Queue(len(cases))
}
for case in cases:
self.queue.put_nowait(case)
if case.parallel:
self.queue['parallel'].put_nowait(case)
else:
self.queue['sequential'].put_nowait(case)
self.succeeded = 0
self.remaining = len(cases)
self.total = len(cases)
Expand All @@ -87,11 +93,11 @@ def Run(self, tasks):
# That way -j1 avoids threading altogether which is a nice fallback
# in case of threading problems.
for i in xrange(tasks - 1):
thread = threading.Thread(target=self.RunSingle, args=[])
thread = threading.Thread(target=self.RunSingle, args=[True])
threads.append(thread)
thread.start()
try:
self.RunSingle()
self.RunSingle(False)
# Wait for the remaining threads
for thread in threads:
# Use a timeout so that signals (ctrl-c) will be processed.
Expand All @@ -105,12 +111,17 @@ def Run(self, tasks):
self.Done()
return not self.failed

def RunSingle(self):
def RunSingle(self, parallel):
while not self.terminate:
try:
test = self.queue.get_nowait()
test = self.queue['parallel'].get_nowait()
except Empty:
return
if parallel:
return
try:
test = self.queue['sequential'].get_nowait()
except Empty:
return
case = test.case
self.lock.acquire()
self.AboutToRun(case)
Expand Down Expand Up @@ -381,6 +392,7 @@ def __init__(self, context, path, arch, mode):
self.duration = None
self.arch = arch
self.mode = mode
self.parallel = False

def IsNegative(self):
return False
Expand Down Expand Up @@ -1068,6 +1080,7 @@ class ClassifiedTest(object):
def __init__(self, case, outcomes):
self.case = case
self.outcomes = outcomes
self.parallel = self.case.parallel


class Configuration(object):
Expand Down

0 comments on commit 682eb7e

Please sign in to comment.