Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
[automl] fix: retry vision_object_detection_predict.predict [(#3492)](G…
Browse files Browse the repository at this point in the history
…oogleCloudPlatform/python-docs-samples#3492)

fixes #3415

Also setting a hard deadline for model deployment.
  • Loading branch information
Takashi Matsuo authored and busunkim96 committed Aug 11, 2020
1 parent cff4874 commit fe00575
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions samples/snippets/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
backoff==1.10.0
pytest==5.3.2
13 changes: 10 additions & 3 deletions samples/snippets/vision_object_detection_predict_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import os

import backoff
from google.api_core.exceptions import DeadlineExceeded
from google.cloud import automl
import pytest

Expand All @@ -32,12 +34,17 @@ def verify_model_state():
if model.deployment_state == automl.enums.Model.DeploymentState.UNDEPLOYED:
# Deploy model if it is not deployed
response = client.deploy_model(model_full_id)
response.result()
response.result(600) # 10 minutes


def test_vision_object_detection_predict(capsys, verify_model_state):
verify_model_state
file_path = "resources/salad.jpg"
vision_object_detection_predict.predict(PROJECT_ID, MODEL_ID, file_path)

# Retry the sample upon DeadlineExceeded, with a hard deadline of 5 mins.
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=300)
def run_sample():
vision_object_detection_predict.predict(PROJECT_ID, MODEL_ID, file_path)

run_sample()
out, _ = capsys.readouterr()
assert "Predicted class name:" in out

0 comments on commit fe00575

Please sign in to comment.