Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/empty dict to dependencies indicating all drivers start concurrently #1103

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions doc/en/multitest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ A MultiTest instance can be constructed from the following parameters:
:py:class:`drivers <testplan.testing.multitest.driver.base.Driver>`.
Drivers on the value side should only start after drivers on the key side are
fully started. When specified, Testplan will try to schedule more drivers
starting parallelly based on the dependencies. Click
:ref:`here <multitest_drivers>` for more information.
starting concurrently based on the dependencies. Drivers included in
``environment`` while not presented in ``dependencies`` will be started
concurrently at the very beginning. Using empty dict here to instruct all
drivers to start concurrently. Click :ref:`here <multitest_drivers>` for more
information.

* **Runtime Information**: The environment always contains a member called
``runtime_info`` which contains information about the current state of the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Users now can make all drivers of a certain ``Test`` start concurrently by passing an empty dict to ``dependencies`` argument.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the dependencies arg doc

3 changes: 1 addition & 2 deletions testplan/testing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ def _set_dependencies(self) -> None:
deps = parse_dependency(self.cfg.dependencies())
else:
deps = self.cfg.dependencies
if deps:
self.resources.set_dependency(deps)
self.resources.set_dependency(deps)

def _start_resource(self) -> None:
if len(self.resources) == 0:
Expand Down
5 changes: 4 additions & 1 deletion testplan/testing/environment/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def __init__(self, parent: Optional["Test"] = None):
self.__dict__["_rt_dependency"]: Optional[DriverDepGraph] = None
self.__dict__["_pocketwatches"]: Dict[str, DriverPocketwatch] = dict()

def set_dependency(self, dependency: DriverDepGraph):
def set_dependency(self, dependency: Optional[DriverDepGraph]):
if dependency is None:
return

for d in dependency.vertices.values():
if (
d.uid() not in self._resources
Expand Down
58 changes: 39 additions & 19 deletions tests/functional/testplan/testing/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,40 +55,60 @@ def __missing__(self, key):
return self[key]


def _assert_orig_dep(env):
assert env.__dict__["_orig_dependency"] is not None


@skip_on_windows(reason="Bash files skipped on Windows.")
@pytest.mark.parametrize(
"driver_dependencies",
"driver_dependencies, use_callable",
[
[("a", "b")],
[("a", "b"), ("b", "c"), ("a", "c")],
[("a", "b"), ("c", "d"), ("a", "d"), ("c", "b")],
([], False),
([], True),
([("a", "b")], False),
([("a", "b"), ("b", "c"), ("a", "c")], True),
([("a", "b"), ("c", "d"), ("a", "d"), ("c", "b")], False),
],
)
def test_testing_environment(mockplan, driver_dependencies, named_temp_file):

def test_testing_environment(
mockplan, named_temp_file, driver_dependencies, use_callable
):
drivers = DriverGeneratorDict(named_temp_file)
dependencies = defaultdict(list)
for k in ["a", "b"]:
drivers[k] = MyDriver(named_temp_file, k)

predicates = list()
for side_a, side_b in driver_dependencies:
dependencies[drivers[side_a]].append(drivers[side_b])
predicates.append(
lambda line_of: line_of[f"{drivers[side_a].name}_POST"]
< line_of[f"{drivers[side_b].name}_PRE"]
)
if driver_dependencies is None:
dependencies = None
else:
dependencies = defaultdict(list)
for side_a, side_b in driver_dependencies:
dependencies[drivers[side_a]].append(drivers[side_b])
predicates.append(
lambda line_of: line_of[f"{drivers[side_a].name}_POST"]
< line_of[f"{drivers[side_b].name}_PRE"]
)

mockplan.add_resource(ProcessPool(name="I'm not local."))
mockplan.schedule(
target=DummyTest(
name="MyTest",
binary=binary_path,
environment=list(drivers.values()),
dependencies=dependencies,
environment=lambda: list(drivers.values())
if use_callable
else list(drivers.values()),
dependencies=lambda: dependencies
if use_callable
else dependencies,
after_start=_assert_orig_dep,
),
resource="I'm not local.",
resource=None,
)
assert mockplan.run().success is True
assert "lifespan" in mockplan.result.report.entries[0].children[0].timer
assert "lifespan" in mockplan.result.report.entries[0].children[1].timer

for i in range(len(drivers)):
assert (
"lifespan" in mockplan.result.report.entries[0].children[i].timer
)

with open(named_temp_file, "r") as f:
lines = f.read().splitlines()
Expand Down