From 1bc8e92efcfa0a846443c4dd55ae8c51f28a6f21 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Sat, 11 Jan 2020 23:00:06 -0500 Subject: [PATCH] launcher: Allow partionning the tests This introduce new command line options, --parts and --part-index. When --parts is set to a value larger then 1, the tests will be split in the same number of group. The group number identified by --part-index will be executed. This is being added in orther to support gliblab CI parallel feature. --- validate/launcher/baseclasses.py | 17 +++++++++++++++++ validate/launcher/main.py | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/validate/launcher/baseclasses.py b/validate/launcher/baseclasses.py index 7dbbb3cf5a..478ef52b26 100644 --- a/validate/launcher/baseclasses.py +++ b/validate/launcher/baseclasses.py @@ -40,6 +40,7 @@ import xml import random import shutil import uuid +from itertools import cycle from .utils import which from . import reporters @@ -1866,6 +1867,13 @@ class _TestsLauncher(Loggable): return testlist_changed + def _split_tests(self, num_groups): + groups = [[] for x in range(num_groups)] + group = cycle(groups) + for test in self.tests: + next(group).append(test) + return groups + def list_tests(self): for tester in self.testers: if not self._tester_needed(tester): @@ -1878,6 +1886,15 @@ class _TestsLauncher(Loggable): self.tests.extend(tests) self.tests.sort(key=lambda test: test.classname) + + if self.options.num_parts < 1: + raise RuntimeError("Tests must be split in positive number of parts.") + if self.options.num_parts > len(self.tests): + raise RuntimeError("Cannot have more parts then there exist tests.") + if self.options.part_index < 1 or self.options.part_index > self.options.num_parts: + raise RuntimeError("Part index is out of range") + + self.tests = self._split_tests(self.options.num_parts)[self.options.part_index - 1] return self.tests def _tester_needed(self, tester): diff --git a/validate/launcher/main.py b/validate/launcher/main.py index 0b1fd46f42..a39bd2298e 100644 --- a/validate/launcher/main.py +++ b/validate/launcher/main.py @@ -530,6 +530,13 @@ class LauncherConfig(Loggable): dir_group.add_argument("--ignore-numfailures", dest="ignore_numfailures", help="Ignore the number of failed test in exit code", default=False, action='store_true') + dir_group.add_argument("--parts", dest="num_parts", + help="Splits the tests in equally distributed parts and only run one part" + " (Defaults to 1 part)", + type=int, default=1) + dir_group.add_argument("--part-index", dest="part_index", + help="The index of the part to be run (starts at 1).", + type=int, default=1) http_server_group = parser.add_argument_group( "Handle the HTTP server to be created")