forked from microsoft/dbt-fabric
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Add remote Spark test orchestration framework #208
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
Draft
sdebruyn
wants to merge
17
commits into
main
Choose a base branch
from
feat/spark-remote-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2b99823
Add remote Spark test orchestration framework (#207)
sdebruyn 14d68d3
Address PR review comments on remote test orchestration
sdebruyn cd44db5
Remove dead --dw forwarding from remote args builder
sdebruyn 3cbce96
Remove --with-grants and --with-python from remote args
sdebruyn eb03e22
Use only IDs for OneLake URLs, drop workspace/lakehouse names
sdebruyn 258393e
Address review comments on remote test orchestration
sdebruyn 40075c8
Use FabricApiClient to resolve workspace/lakehouse by name or ID
sdebruyn 8dc317e
Use FabricSparkCredentials with database field for lakehouse
sdebruyn 10ea1df
Document remote Spark test execution in CONTRIBUTING.md
sdebruyn a9b908c
Reuse FabricApiClient in SparkJobClient instead of custom HTTP plumbing
sdebruyn ec532b9
Add docstrings to all spark_remote functions and classes
sdebruyn 82f6096
Isolate concurrent remote runs with per-run ID
sdebruyn e4b6bc8
Split project namespace (per-worktree) from artifact namespace (per-run)
sdebruyn 62b1191
Address code review: expose public API on FabricApiClient, fix edge c…
sdebruyn 2dc6de8
Address second round of PR review comments
sdebruyn abd28f8
Remove private API method wrappers from FabricApiClient
sdebruyn c114548
Replace custom XML parsing with junitparser library
sdebruyn 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Empty file.
This file contains hidden or 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,82 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from uuid import uuid4 | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.spark_remote.orchestrator import RemoteTestOrchestrator | ||
| from tests.spark_remote.result_reporter import report_remote_results | ||
|
|
||
|
|
||
| def remote_runtestloop(session: pytest.Session) -> bool: | ||
| """Replace pytest's default test loop with remote Spark execution. | ||
|
|
||
| Generates a unique run ID per invocation (for artifact isolation) and | ||
| derives a stable worktree key from the project root (for incremental | ||
| project sync). Multiple agents in separate worktrees can run concurrently | ||
| without interference. | ||
|
|
||
| Args: | ||
| session: The pytest Session (already collected). | ||
|
|
||
| Returns: | ||
| True to signal that the test loop has been handled. | ||
| """ | ||
| if session.config.option.collectonly: | ||
| return True | ||
|
|
||
| if not session.items: | ||
| return True | ||
|
|
||
| run_id = uuid4().hex[:8] | ||
| remote_args = _build_remote_args(session) | ||
|
|
||
| orchestrator = RemoteTestOrchestrator.from_env(run_id) | ||
| print( | ||
| f"\nRemote execution [run={run_id}, worktree={orchestrator._worktree_key}]:" | ||
| f" syncing project to lakehouse..." | ||
| ) | ||
| orchestrator.sync_project() | ||
|
|
||
| print(f"\nRemote execution [run={run_id}]: submitting Spark job...") | ||
| job_result = orchestrator.run_spark_job(remote_args) | ||
|
|
||
| print(f"\n {job_result.status} — downloading results...") | ||
| results_path = orchestrator.download_results() | ||
| report_remote_results(session, results_path, job_result) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| def _build_remote_args(session: pytest.Session) -> list[str]: | ||
| """Extract relevant pytest options from the local session for remote forwarding. | ||
|
|
||
| Forwards -k, -v, --de, -x, and positional test paths. The --junitxml path | ||
| is set by the remote entry point based on the run ID. | ||
|
|
||
| Args: | ||
| session: The local pytest Session to extract options from. | ||
|
|
||
| Returns: | ||
| List of CLI arguments to pass to the remote pytest invocation. | ||
| """ | ||
| args: list[str] = [] | ||
| config = session.config | ||
|
|
||
| if config.getoption("-k"): | ||
| args.extend(["-k", config.getoption("-k")]) | ||
|
|
||
| if config.getoption("verbose", 0) > 0: | ||
| args.append("-" + "v" * config.getoption("verbose")) | ||
|
|
||
| if config.getoption("--de", default=False): | ||
| args.append("--de") | ||
|
|
||
| if config.getoption("-x", default=False): | ||
| args.append("-x") | ||
|
sdebruyn marked this conversation as resolved.
|
||
|
|
||
|
sdebruyn marked this conversation as resolved.
|
||
| positional = config.args | ||
| if positional: | ||
| args.extend(positional) | ||
|
|
||
| return args | ||
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.
Uh oh!
There was an error while loading. Please reload this page.