Skip to content

Commit

Permalink
chore: Refactor test (#131)
Browse files Browse the repository at this point in the history
* chore: added retry on flaky video service

* chore: refactored the test so that it only retry on service unavailable exception

* chore: added ceiling for while loop

* lint

* reverted some files

* reverted the changes on noxfile

* added newline noxfile

* fixed imports order

* ran nox
  • Loading branch information
munkhuushmgl committed Apr 30, 2021
1 parent bda1bee commit 6721481
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions videointelligence/samples/analyze/analyze_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import time

from google.api_core.exceptions import ServiceUnavailable

import pytest

import analyze
Expand Down Expand Up @@ -57,9 +61,19 @@ def test_analyze_labels_file(capsys):

@pytest.mark.slow
def test_analyze_explicit_content(capsys):
analyze.analyze_explicit_content("gs://cloud-samples-data/video/cat.mp4")
out, _ = capsys.readouterr()
assert "pornography" in out
try_count = 0
while try_count < 3:
try:
analyze.analyze_explicit_content("gs://cloud-samples-data/video/cat.mp4")
out, _ = capsys.readouterr()
assert "pornography" in out
except ServiceUnavailable as e:
# Service is throttling or not available for the moment, sleep for 5 sec and retrying again.
print("Got service unavailable exception: {}".format(str(e)))
time.sleep(5)
continue
try_count = try_count + 1
break


@pytest.mark.slow
Expand Down

0 comments on commit 6721481

Please sign in to comment.