-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
airbyte-ci: Introduce --only-step
option for connector tests
#34276
Merged
alafanechere
merged 2 commits into
master
from
augustin/01-15-airbyte-ci_Introduce_--only-step_option_for_connector_tests
Jan 16, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
import inspect | ||
from dataclasses import dataclass, field | ||
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, List, Tuple, Union | ||
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, List, Optional, Set, Tuple, Union | ||
|
||
import anyio | ||
import asyncer | ||
|
@@ -27,16 +27,78 @@ class InvalidStepConfiguration(Exception): | |
pass | ||
|
||
|
||
def _get_dependency_graph(steps: STEP_TREE) -> Dict[str, List[str]]: | ||
""" | ||
Get the dependency graph of a step tree. | ||
""" | ||
dependency_graph: Dict[str, List[str]] = {} | ||
for step in steps: | ||
if isinstance(step, StepToRun): | ||
dependency_graph[step.id] = step.depends_on | ||
elif isinstance(step, list): | ||
nested_dependency_graph = _get_dependency_graph(list(step)) | ||
dependency_graph = {**dependency_graph, **nested_dependency_graph} | ||
else: | ||
raise Exception(f"Unexpected step type: {type(step)}") | ||
|
||
return dependency_graph | ||
|
||
|
||
def _get_transitive_dependencies_for_step_id( | ||
dependency_graph: Dict[str, List[str]], step_id: str, visited: Optional[Set[str]] = None | ||
) -> List[str]: | ||
"""Get the transitive dependencies for a step id. | ||
|
||
Args: | ||
dependency_graph (Dict[str, str]): The dependency graph to use. | ||
step_id (str): The step id to get the transitive dependencies for. | ||
visited (Optional[Set[str]], optional): The set of visited step ids. Defaults to None. | ||
|
||
Returns: | ||
List[str]: List of transitive dependencies as step ids. | ||
""" | ||
if visited is None: | ||
visited = set() | ||
|
||
if step_id not in visited: | ||
visited.add(step_id) | ||
|
||
dependencies: List[str] = dependency_graph.get(step_id, []) | ||
for dependency in dependencies: | ||
dependencies.extend(_get_transitive_dependencies_for_step_id(dependency_graph, dependency, visited)) | ||
|
||
return dependencies | ||
else: | ||
return [] | ||
|
||
|
||
@dataclass | ||
class RunStepOptions: | ||
"""Options for the run_step function.""" | ||
|
||
fail_fast: bool = True | ||
skip_steps: List[str] = field(default_factory=list) | ||
keep_steps: List[str] = field(default_factory=list) | ||
log_step_tree: bool = True | ||
concurrency: int = 10 | ||
step_params: Dict[CONNECTOR_TEST_STEP_ID, STEP_PARAMS] = field(default_factory=dict) | ||
|
||
def __post_init__(self) -> None: | ||
if self.skip_steps and self.keep_steps: | ||
raise ValueError("Cannot use both skip_steps and keep_steps at the same time") | ||
|
||
def get_step_ids_to_skip(self, runnables: STEP_TREE) -> List[str]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❗This is all great. Only thing thats missing is some tests to ensure weve got the traversal correct |
||
if self.skip_steps: | ||
return self.skip_steps | ||
if self.keep_steps: | ||
step_ids_to_keep = set(self.keep_steps) | ||
dependency_graph = _get_dependency_graph(runnables) | ||
all_step_ids = set(dependency_graph.keys()) | ||
for step_id in self.keep_steps: | ||
step_ids_to_keep.update(_get_transitive_dependencies_for_step_id(dependency_graph, step_id)) | ||
return list(all_step_ids - step_ids_to_keep) | ||
return [] | ||
|
||
|
||
@dataclass(frozen=True) | ||
class StepToRun: | ||
|
@@ -217,6 +279,7 @@ async def run_steps( | |
if not runnables: | ||
return results | ||
|
||
step_ids_to_skip = options.get_step_ids_to_skip(runnables) | ||
# Log the step tree | ||
if options.log_step_tree: | ||
main_logger.info(f"STEP TREE: {runnables}") | ||
|
@@ -232,7 +295,7 @@ async def run_steps( | |
steps_to_evaluate, remaining_steps = _get_next_step_group(runnables) | ||
|
||
# Remove any skipped steps | ||
steps_to_run, results = _filter_skipped_steps(steps_to_evaluate, options.skip_steps, results) | ||
steps_to_run, results = _filter_skipped_steps(steps_to_evaluate, step_ids_to_skip, results) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😍 |
||
|
||
# Run all steps in list concurrently | ||
semaphore = anyio.Semaphore(options.concurrency) | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍