Skip to content

Commit 6721481

Browse files
authored
chore: Refactor test (#131)
* 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
1 parent bda1bee commit 6721481

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

videointelligence/samples/analyze/analyze_test.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import time
18+
19+
from google.api_core.exceptions import ServiceUnavailable
20+
1721
import pytest
1822

1923
import analyze
@@ -57,9 +61,19 @@ def test_analyze_labels_file(capsys):
5761

5862
@pytest.mark.slow
5963
def test_analyze_explicit_content(capsys):
60-
analyze.analyze_explicit_content("gs://cloud-samples-data/video/cat.mp4")
61-
out, _ = capsys.readouterr()
62-
assert "pornography" in out
64+
try_count = 0
65+
while try_count < 3:
66+
try:
67+
analyze.analyze_explicit_content("gs://cloud-samples-data/video/cat.mp4")
68+
out, _ = capsys.readouterr()
69+
assert "pornography" in out
70+
except ServiceUnavailable as e:
71+
# Service is throttling or not available for the moment, sleep for 5 sec and retrying again.
72+
print("Got service unavailable exception: {}".format(str(e)))
73+
time.sleep(5)
74+
continue
75+
try_count = try_count + 1
76+
break
6377

6478

6579
@pytest.mark.slow

0 commit comments

Comments
 (0)