Skip to content
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

[vision] testing: retry upon errors #3764

Merged
merged 2 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions vision/cloud-client/detect/detect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import uuid

import backoff
from google.cloud import storage
import pytest

Expand Down Expand Up @@ -142,19 +143,40 @@ def test_detect_properties_uri(capsys):
assert 'frac' in out


def only_sample_error(e):
"""A callback for giving up upon Exceptions.

Giving up upon any Exceptions other than the ones that sample code
throws at the end of the function.
"""
return 'https://cloud.google.com/apis/design/errors' not in str(e)


# Vision 1.1 tests
def test_detect_web(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/landmark.jpg')
detect.detect_web(file_name)

@backoff.on_exception(
backoff.expo, Exception, max_time=60, giveup=only_sample_error)
def run_sample():
detect.detect_web(file_name)

run_sample()
out, _ = capsys.readouterr()
assert 'best guess label: palace of fine arts' in out.lower()


def test_detect_web_uri(capsys):
file_name = 'gs://{}/vision/landmark/pofa.jpg'.format(ASSET_BUCKET)
detect.detect_web_uri(file_name)

@backoff.on_exception(
backoff.expo, Exception, max_time=60, giveup=only_sample_error)
def run_sample():
detect.detect_web_uri(file_name)

run_sample()
out, _ = capsys.readouterr()
assert 'best guess label: palace of fine arts' in out.lower()

Expand All @@ -163,15 +185,27 @@ def test_detect_web_with_geo(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/city.jpg')
detect.web_entities_include_geo_results(file_name)

@backoff.on_exception(
backoff.expo, Exception, max_time=60, giveup=only_sample_error)
def run_sample():
detect.web_entities_include_geo_results(file_name)

run_sample()
out, _ = capsys.readouterr()
out = out.lower()
assert 'description' in out


def test_detect_web_with_geo_uri(capsys):
file_name = 'gs://{}/vision/web/city.jpg'.format(ASSET_BUCKET)
detect.web_entities_include_geo_results_uri(file_name)

@backoff.on_exception(
backoff.expo, Exception, max_time=60, giveup=only_sample_error)
def run_sample():
detect.web_entities_include_geo_results_uri(file_name)

run_sample()
out, _ = capsys.readouterr()
out = out.lower()
assert 'description' in out
Expand Down
1 change: 1 addition & 0 deletions vision/cloud-client/detect/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
backoff==1.10.0
pytest==5.3.2
flaky==3.6.1