Training job unit tests can outlive their service mocks and hang teardown
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 AutoML forecasting、image、tabular、text 和 video 单元测试文件中的 test_run_called_twice_raises,以及自定义训练作业测试中的 test_run_returns_none_if_no_model_to_upload 开始。在每个异步用例中,于重复运行的断言之后使用 job.wait() 等待第一个作业,这与无同步的自定义训练测试已有的做法一致。运行 issue 中的诊断脚本。当全部 22 个用例通过,且 teardown 不再等待真实的 pipeline 客户端重试时,即为完成。
由索引模型根据 Issue 内容生成。
描述
The async cases of test_run_called_twice_raises in the AutoML forecasting, image, tabular, text and video modules can return while the first training job is still running. The second run() correctly raises RuntimeError, but the test does not wait for the first job before pytest removes the service mocks.
The same lifetime issue also occurs in test_run_returns_none_if_no_model_to_upload for CustomTrainingJob, CustomContainerTrainingJob and CustomPythonPackageTrainingJob. Those tests assert that run() returns None, then return without joining the job.
During a bounded investigation, a forecasting worker entered the real PipelineServiceClient.get_training_pipeline after those mocks were removed, while class teardown waited in initializer.global_pool.shutdown(wait=True). This blocked the unit-test run on RPC retries in an offline environment. A subsequent parallel run also captured a real pipeline-client retry during the custom-container no-model test, whose teardown took 80.49 seconds despite the test ultimately being reported as passed.
Environment
- Current main:
7f08bd6c1dbb99f8a00922ae13c488bda3ece7b9. - Debian 12 container, Linux/WSL2, CPython 3.14.7, pip 26.2.1.
- SDK imported from the checkout (
2.4.0), with the standard unit-test dependencies. No cloud credentials or external network. - The existing environment's
pip checkreports invalid MLflow optional-extra metadata (scikit-learn >=1.0.*) on both unchanged and modified main;uv pip checkpasses. No dependency versions were changed for this investigation.
Reproduction
The ordinary hang depends on worker scheduling. The diagnostic below makes the lifetime error deterministic for the existing SequenceToSequencePlusForecastingTrainingJob-False case. It holds the worker just before model lookup, preserves the original duplicate-run assertion, and checks for unfinished work when the test returns. It then releases and joins the worker while the service mocks are still active, so the diagnostic fails rather than hanging in teardown.
Save the script outside the checkout as /tmp/automl-lifetime-repro.py, then run from the repository root in its unit-test environment:
python -I -B /tmp/automl-lifetime-repro.py
Expected: background work completes before the test returns. On the main commit above, the script fails with AssertionError: Test returned with background work pending. Adding an async job.wait() after the existing exception assertion makes it pass. The same barrier check across the five AutoML modules and the three custom no-model methods found 11 failing async cases and 11 passing sync cases; all 22 pass with the final cleanup, and removing the cleanup restores the same 11 failures.
Standalone diagnostic (verified on unchanged main and with the cleanup)
"""Run from the repository root with its unit-test dependencies installed."""
import inspect
from pathlib import Path
import sys
import threading
from unittest import mock
import pytest
sys.path.insert(0, str(Path.cwd()))
from google.cloud.aiplatform import base, training_jobs
class LifetimeCheck:
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_call(self, item):
entered, release = threading.Event(), threading.Event()
jobs = []
original_get = training_jobs._TrainingJob._get_model
original_wait = base.FutureManager.wait
def held_get(job, *args, **kwargs):
if threading.current_thread() is not threading.main_thread():
jobs.append(job)
entered.set()
assert release.wait(10), "Worker barrier expired"
return original_get(job, *args, **kwargs)
def explicit_wait(job):
release.set()
return original_wait(job)
with mock.patch.object(training_jobs._TrainingJob, "_get_model", held_get), mock.patch.object(base.FutureManager, "wait", explicit_wait):
outcome = yield
observed = entered.wait(5)
completed = observed and all(job._are_futures_done() for job in jobs)
# Safely finish the worker while the test's service mocks still exist.
release.set()
for job in jobs:
original_wait(job)
outcome.get_result()
assert observed, "Worker did not reach the model boundary"
assert completed, "Test returned with background work pending"
print("SDK source:", inspect.getfile(training_jobs), flush=True)
raise SystemExit(pytest.main([
"-q", "-p", "no:warnings", "-p", "no:cacheprovider",
"tests/unit/aiplatform/test_automl_forecasting_training_jobs.py::"
"TestForecastingTrainingJob::test_run_called_twice_raises"
"[SequenceToSequencePlusForecastingTrainingJob-False]",
], plugins=[LifetimeCheck()]))
I have a local test-only cleanup that adds if not sync: job.wait() after the existing assertion in these eight methods across six files. The three equivalent custom-training duplicate-run tests already use that pattern. Would this be an appropriate focused test-cleanup contribution?
- 主要语言
- Python
- 星标
- 907
- 派生
- 469
- 平均合并
- 1 天 14 小时
- 30 天内合并 PR
- 37
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
googleapis/python-aiplatform 的其他 Issue
-
Protobuf 7.35.1+ support可能已有人在做 @garethknowles 于 32 天前认领。 未关闭api: vertex-ai
难度 1/5 1 小时以内 新手友好度 85/100
googleapis/python-aiplatform#7132 · 1 个 reaction ·
维护者通常 1 天内回复
-
AgentEngineConfig.agent_framework Literal rejects "a2a" — out of sync with _SUPPORTED_AGENT_FRAMEWORKS and the GA A2A template可能重新可做 关联的 PR 已关闭且未合并。 未关闭api: vertex-ai
难度 2/5 1-3 小时 新手友好度 78/100
googleapis/python-aiplatform#7097 ·
维护者通常 1 天内回复
-
CustomContainerTrainingJob.run drops max_wait_duration=0 instead of requesting indefinite DWS wait可能已有人在做 @hugosmoreira 于 60 天前认领。 未关闭api: vertex-ai
难度 2/5 1-3 小时 新手友好度 78/100
googleapis/python-aiplatform#7067 · 1 条评论 ·
维护者通常 1 天内回复
-
`A2aAgent` builds agent-card `url` from default region (us-central1), ignoring `GOOGLE_CLOUD_AGENT_ENGINE_LOCATION`可能已有人在做 @sushicw 于 123 天前认领。 未关闭api: vertex-ai
难度 2/5 1-3 小时 新手友好度 68/100
googleapis/python-aiplatform#6877 ·
维护者通常 1 天内回复
-
api: vertex-ai
难度 2/5 1-3 小时 新手友好度 68/100
googleapis/python-aiplatform#6865 · 1 条评论 ·
维护者通常 1 天内回复
查看 googleapis/python-aiplatform 的全部 Issue
相似的 Issue
-
enhancement from-review
难度 2/5 1-3 小时 新手友好度 78/100
khuisman/mcp-gee-sweet#1010 ·
维护者通常 1 天内回复
-
bug confirmed issue
难度 2/5 1-3 小时 新手友好度 72/100
open-webui/open-webui#32333 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
ll7/robot_sf_ll7#10368 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
-
难度 2/5 1-3 小时 新手友好度 68/100
flop-labs/technocore-chat#982 ·
维护者通常 1 天内回复