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
Changes from 1 commit
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
Prev Previous commit
address review comments
zhenyu-ms committed Jun 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 512b09d8b865555306325a336087edea94c998bf
7 changes: 5 additions & 2 deletions doc/en/multitest.rst
Original file line number Diff line number Diff line change
@@ -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
8 changes: 3 additions & 5 deletions testplan/testing/base.py
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ def get_options(cls):
[Or(Resource, RemoteDriver)], validate_func()
),
ConfigOption("dependencies", default=None): Or(
None, Use(parse_dependency), validate_func()
Use(parse_dependency), validate_func()
),
ConfigOption("initial_context", default={}): Or(
dict, validate_func()
@@ -437,12 +437,10 @@ def _build_environment(self) -> None:

def _set_dependencies(self) -> None:
if callable(self.cfg.dependencies):
ret = self.cfg.dependencies()
deps = parse_dependency(ret) if ret is not None else None
deps = parse_dependency(self.cfg.dependencies())
else:
deps = self.cfg.dependencies
if deps is not None:
self.resources.set_dependency(deps)
self.resources.set_dependency(deps)

def _start_resource(self) -> None:
if len(self.resources) == 0:
5 changes: 4 additions & 1 deletion testplan/testing/environment/base.py
Original file line number Diff line number Diff line change
@@ -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
28 changes: 12 additions & 16 deletions tests/functional/testplan/testing/test_environment.py
Original file line number Diff line number Diff line change
@@ -56,27 +56,22 @@ def __missing__(self, key):


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


@skip_on_windows(reason="Bash files skipped on Windows.")
@pytest.mark.parametrize(
"driver_dependencies, is_lift, is_set",
"driver_dependencies, use_callable",
[
(None, False, False),
(None, True, False),
([], False, True),
([], True, True),
([("a", "b")], False, True),
([("a", "b"), ("b", "c"), ("a", "c")], True, True),
([("a", "b"), ("c", "d"), ("a", "d"), ("c", "b")], False, True),
([], 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, named_temp_file, driver_dependencies, is_lift, is_set
mockplan, named_temp_file, driver_dependencies, use_callable
):
drivers = DriverGeneratorDict(named_temp_file)
for k in ["a", "b"]:
@@ -98,11 +93,12 @@ def test_testing_environment(
target=DummyTest(
name="MyTest",
binary=binary_path,
initial_context={"is_set": is_set},
environment=lambda: list(drivers.values())
if is_lift
if use_callable
else list(drivers.values()),
dependencies=lambda: dependencies if is_lift else dependencies,
dependencies=lambda: dependencies
if use_callable
else dependencies,
after_start=_assert_orig_dep,
),
resource=None,