Training job unit tests can outlive their service mocks and hang teardown
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 72/100
Rechercherichtung
Beginne mit test_run_called_twice_raises in den Unit-Testdateien für AutoML-Forecasting, Image, Tabular, Text und Video sowie mit test_run_returns_none_if_no_model_to_upload in den Tests für Custom-Training-Jobs. Rufe in jedem asynchronen Fall nach der Assertion zum doppelten Lauf job.wait() auf, um den ersten Job zu joinen, wie es die synchronisationsfreien Custom-Training-Tests bereits tun. Führe das Diagnoseskript aus dem Issue aus. Fertig ist es, wenn es für alle 22 Fälle durchläuft und das Teardown nicht mehr auf echte Wiederholungsversuche des Pipeline-Clients wartet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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?
- Vorherrschende Sprache
- Python
- Sterne
- 909
- Forks
- 469
- Ø Merge
- 1 T. 14 Std.
- Gemergte PRs (30 T.)
- 37
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus googleapis/python-aiplatform
-
Protobuf 7.35.1+ supportEvtl. vergeben @garethknowles hat das vor 35 Tagen übernommen. Offenapi: vertex-ai
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
googleapis/python-aiplatform#7132 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
AgentEngineConfig.agent_framework Literal rejects "a2a" — out of sync with _SUPPORTED_AGENT_FRAMEWORKS and the GA A2A templateEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offenapi: vertex-ai
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
googleapis/python-aiplatform#7097 ·
Maintainer antworten meist innerhalb von 1 Tag
-
CustomContainerTrainingJob.run drops max_wait_duration=0 instead of requesting indefinite DWS waitEvtl. vergeben @hugosmoreira hat das vor 63 Tagen übernommen. Offenapi: vertex-ai
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
googleapis/python-aiplatform#7067 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
`A2aAgent` builds agent-card `url` from default region (us-central1), ignoring `GOOGLE_CLOUD_AGENT_ENGINE_LOCATION`Evtl. vergeben @sushicw hat das vor 126 Tagen übernommen. Offenapi: vertex-ai
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
googleapis/python-aiplatform#6877 ·
Maintainer antworten meist innerhalb von 1 Tag
-
api: vertex-ai
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
googleapis/python-aiplatform#6865 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in googleapis/python-aiplatform
Ähnliche Issues
-
documentation good first issue
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 72/100
sujithputta02/Esapay#13 ·
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag
-
Flaky: credential-proxy admission metric test asserts a wall-clock bound it does not establishOffenneeds-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
gke-labs/kube-agents#3277 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
jbacalso24/mimry#291 ·
Maintainer antworten meist innerhalb von 1 Tag
-
good first issue
Schwierigkeit 2/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
eli-alvarado/us-watchlist-alerts#14 ·
Maintainer antworten meist innerhalb von 1 Tag