Skip to content

Commit

Permalink
[automl] fix: retry vision_object_detection_predict.predict (#3492)
Browse files Browse the repository at this point in the history
fixes #3415

Also setting a hard deadline for model deployment.
  • Loading branch information
Takashi Matsuo authored Apr 24, 2020
1 parent 00a395d commit 86a552c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions automl/cloud-client/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 automl/cloud-client/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 86a552c

Please sign in to comment.