Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Fix: #254 by increasing timeout, use backoff module instead of flaky #271

Merged
merged 5 commits into from
Oct 11, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
/samples/**/*.py @googleapis/cdpe-cloudai

# The python-samples-owners team is the default owner for samples
/samples/**/*.py @telpirion @sirtorry @googleapis/python-samples-owners
/samples/**/*.py @aribray @googleapis/python-samples-owners
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 All @@ -25,8 +26,7 @@
GLOSSARY_ID = "DO_NOT_DELETE_TEST_GLOSSARY"


@pytest.fixture(scope="function")
def bucket():
def get_ephemeral_bucket():
"""Create a temporary bucket to store annotation output."""
bucket_name = f"tmp-{uuid.uuid4().hex}"
storage_client = storage.Client()
Expand All @@ -37,15 +37,30 @@ def bucket():
bucket.delete(force=True)


@pytest.mark.flaky(max_runs=3, min_passes=1)
@pytest.fixture(scope="function")
def bucket():
"""Create a bucket feature for testing"""
return next(get_ephemeral_bucket())


def on_backoff(invocation_dict):
"""Backoff callback; create a testing bucket for each backoff run"""
invocation_dict['kwargs']['bucket'] = next(get_ephemeral_bucket())


nicain marked this conversation as resolved.
Show resolved Hide resolved
# If necessary, retry test function while backing off the timeout sequentially
MAX_TIMEOUT = 500


@backoff.on_exception(wait_gen=lambda : iter([100, 250, 300, MAX_TIMEOUT]), exception=Exception, max_tries=5, on_backoff=on_backoff)
def test_batch_translate_text_with_glossary(capsys, bucket):

translate_v3_batch_translate_text_with_glossary.batch_translate_text_with_glossary(
"gs://cloud-samples-data/translation/text_with_glossary.txt",
"gs://{}/translation/BATCH_TRANSLATION_GLOS_OUTPUT/".format(bucket.name),
PROJECT_ID,
GLOSSARY_ID,
320,
)
MAX_TIMEOUT)

out, _ = capsys.readouterr()
assert "Total Characters: 9" in out