-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vdk-meta-jobs: address review comments
Signed-off-by: Antoni Ivanov <[email protected]>
- Loading branch information
1 parent
15893a5
commit 99cbae4
Showing
8 changed files
with
153 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
projects/vdk-plugins/vdk-meta-jobs/src/vdk/plugin/meta_jobs/remote_data_job_executor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
projects/vdk-plugins/vdk-meta-jobs/tests/jobs/meta-job-circular-dep/config.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[owner] | ||
team = team-awesome |
20 changes: 20 additions & 0 deletions
20
projects/vdk-plugins/vdk-meta-jobs/tests/jobs/meta-job-circular-dep/meta.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2021 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import logging | ||
|
||
from vdk.api.job_input import IJobInput | ||
from vdk.plugin.meta_jobs.meta_job_runner import MetaJobInput | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def run(job_input: IJobInput): | ||
log.info(f"Dummy arguments {job_input.get_arguments()}") | ||
|
||
# circular dependency: | ||
# job2 depends on job4 which depends on job3 which depends on job2 | ||
job1 = dict(job_name="job1", depends_on=[]) | ||
job2 = dict(job_name="job2", depends_on=["job1", "job4"]) | ||
job3 = dict(job_name="job3", depends_on=["job1", "job2"]) | ||
job4 = dict(job_name="job4", depends_on=["job3"]) | ||
MetaJobInput().run_meta_job([job1, job2, job3, job4]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Copyright 2021 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import time | ||
from unittest.mock import call | ||
from unittest.mock import MagicMock | ||
|
||
from vdk.plugin.meta_jobs.cached_data_job_executor import TrackingDataJobExecutor | ||
from vdk.plugin.meta_jobs.meta_dag import MetaJobsDag | ||
|
||
# We overall eschew unit tests in favor of functional tests in test_meta_job | ||
# Still some functionalities are more easily tested in unit tests so we add here some. | ||
|
||
|
||
def test_execute_dag_happy_case(): | ||
job1 = dict(job_name="job1", depends_on=[]) | ||
job2 = dict(job_name="job2", depends_on=["job1"]) | ||
job3 = dict(job_name="job3", depends_on=["job1"]) | ||
job4 = dict(job_name="job4", depends_on=["job2", "job3"]) | ||
jobs = [job1, job2, job3, job4] | ||
|
||
dag = MetaJobsDag("team") | ||
dag.build_dag(jobs) | ||
dag._job_executor = MagicMock(spec=TrackingDataJobExecutor) | ||
dag._job_executor.get_finished_job_names.side_effect = [ | ||
["job1"], | ||
["job2", "job3"], | ||
["job4"], | ||
] | ||
|
||
dag.execute_dag() | ||
|
||
assert [ | ||
call("job1"), | ||
call("job2"), | ||
call("job3"), | ||
call("job4"), | ||
] == dag._job_executor.start_job.call_args_list | ||
|
||
|
||
def test_execute_dag_busyloop(): | ||
job1 = dict(job_name="job1", depends_on=[]) | ||
job2 = dict(job_name="job2", depends_on=["job1"]) | ||
job3 = dict(job_name="job3", depends_on=["job1"]) | ||
jobs = [job1, job2, job3] | ||
|
||
dag = MetaJobsDag("team") | ||
dag.build_dag(jobs) | ||
dag._job_executor = MagicMock(spec=TrackingDataJobExecutor) | ||
dag._dag_execution_check_time_period_seconds = 3 | ||
|
||
calls = [0] | ||
start_time = [0] | ||
|
||
def mock_get_finished_job_names(*args, **kwargs): | ||
calls[0] += 1 | ||
if calls[0] == 1: | ||
start_time[0] = time.time() | ||
return ["job1"] | ||
elif time.time() - start_time[0] > 2: | ||
return ["job2", "job3"] | ||
else: | ||
return [] | ||
|
||
dag._job_executor.get_finished_job_names.side_effect = mock_get_finished_job_names | ||
|
||
dag.execute_dag() | ||
|
||
# check for busyloop (this would have been called hundreds of times if there is busyloop bug) | ||
assert calls[0] <= 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters