-
Notifications
You must be signed in to change notification settings - Fork 12
test: Add test that executes a colab notebook that uses spark connect #151
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
Merged
jinnthehuman
merged 5 commits into
GoogleCloudDataproc:jameshonglee-e2e-test
from
jinnthehuman:addTest
Oct 16, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cbe5d45
Add test that executes a colab notebook that uses spark connect
jinnthehuman b43fb75
Fix formatting and add requirements file
jinnthehuman 3dfdbb5
Actually add requirements file
jinnthehuman 37149c2
Make job state validation more robust
jinnthehuman 4b796ce
Fix linting
jinnthehuman 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| pytest>=8.0 | ||
| pytest-xdist>=3.0 | ||
| google-cloud-aiplatform>=1.119.0 |
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,118 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from google.cloud import aiplatform_v1 | ||
| from google.cloud.aiplatform_v1.types import JobState | ||
|
|
||
| import os | ||
| import uuid | ||
| import pytest | ||
| import logging | ||
|
|
||
| LOGGER = logging.getLogger(__name__) | ||
|
|
||
| REPOSITORY_ID = "97193e1e-c5d1-4ce8-bc6f-cf206c701624" | ||
| TEMPLATE_ID = "6409629422399258624" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def test_project(): | ||
| return os.getenv("GOOGLE_CLOUD_PROJECT") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def test_region(): | ||
| return os.getenv("GOOGLE_CLOUD_REGION") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def test_service_account(): | ||
| return os.getenv("SERVICE_ACCOUNT") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def test_template(): | ||
| return TEMPLATE_ID | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def test_repository(): | ||
| return REPOSITORY_ID | ||
|
|
||
|
|
||
| def test_executing_colab_notebook( | ||
| test_project, | ||
| test_region, | ||
| test_service_account, | ||
| test_template, | ||
| test_repository, | ||
| ): | ||
| """Test executing a Colab notebook that uses Spark Connect.""" | ||
| test_api_endpoint = f"{test_region}-aiplatform.googleapis.com" | ||
| test_parent = f"projects/{test_project}/locations/{test_region}" | ||
| test_execution_display_name = ( | ||
| f"spark-connect-e2e-notebook-test-{uuid.uuid4().hex}" | ||
| ) | ||
|
|
||
| LOGGER.info( | ||
| f"Starting notebook execution job with display name: {test_execution_display_name}" | ||
| ) | ||
|
|
||
| notebook_service_client = aiplatform_v1.NotebookServiceClient( | ||
| client_options={ | ||
| "api_endpoint": test_api_endpoint, | ||
| } | ||
| ) | ||
|
|
||
| operation = notebook_service_client.create_notebook_execution_job( | ||
| parent=test_parent, | ||
| notebook_execution_job={ | ||
| "display_name": test_execution_display_name, | ||
| # Specify a NotebookRuntimeTemplate to source compute configuration from | ||
| "notebook_runtime_template_resource_name": f"projects/{test_project}/locations/{test_region}/notebookRuntimeTemplates/{test_template}", | ||
| # Specify a Colab Enterprise notebook to run | ||
| "dataform_repository_source": { | ||
| "dataform_repository_resource_name": f"projects/{test_project}/locations/{test_region}/repositories/{test_repository}", | ||
| }, | ||
| "gcs_notebook_source": { | ||
| "uri": "gs://e2e-testing-bucket/input/notebooks/spark_connect_e2e_notebook_test.ipynb", | ||
| }, | ||
| # Specify a Cloud Storage bucket to store output artifacts | ||
| "gcs_output_uri": "gs://e2e-testing-bucket/output", | ||
| # Run as the service account instead | ||
| "service_account": f"{test_service_account}", | ||
| }, | ||
| ) | ||
| LOGGER.info("Waiting for operation to complete...") | ||
|
|
||
| result = operation.result() | ||
| LOGGER.info(f"Notebook execution uri: {result}") | ||
|
|
||
| notebook_execution_jobs = ( | ||
| notebook_service_client.list_notebook_execution_jobs(parent=test_parent) | ||
| ) | ||
| executed_job = list( | ||
| filter( | ||
| lambda job: job.display_name == test_execution_display_name, | ||
| notebook_execution_jobs, | ||
| ) | ||
| ) | ||
|
|
||
| assert len(executed_job) == 1 | ||
| executed_job = executed_job[0] | ||
|
|
||
| LOGGER.info(executed_job) | ||
|
|
||
| LOGGER.info(f"Job status: {executed_job.job_state}") | ||
| assert executed_job.job_state == JobState.JOB_STATE_SUCCEEDED | ||
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.
The test contains several hardcoded values like
REPOSITORY_IDandTEMPLATE_ID(and GCS URIs on lines 70 and 74). This makes the test less flexible and harder to maintain or reuse in different environments. Consider moving these values to environment variables, similar to howGOOGLE_CLOUD_PROJECTis handled.