Skip to content

Commit bb1c1df

Browse files
author
Ace Nassri
authored
chore(GAE Python3): add HTTP retries to flaky test (#8882)
* chore(GAE Python3): add HTTP retries to flaky test Fixes #8852 * Use backoff + requests.raise_for_status() * Propagate changes to other samples
1 parent a85dbe9 commit bb1c1df

File tree

9 files changed

+81
-2
lines changed

9 files changed

+81
-2
lines changed

appengine/standard_python3/bundled-services/blobstore/django/main_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ def version():
6565
result = gcloud_cli(f"app deploy --no-promote --version={uuid.uuid4().hex}")
6666
version_id = result["versions"][0]["id"]
6767
project_id = result["versions"][0]["project"]
68+
version_hostname = f"{version_id}-dot-{project_id}.appspot.com"
69+
70+
# Wait for app to initialize
71+
@backoff.on_exception(backoff.expo, requests.exceptions.HTTPError, max_tries=3)
72+
def wait_for_app(url):
73+
r = requests.get(url)
74+
r.raise_for_status()
75+
76+
wait_for_app(f"https://{version_hostname}/")
6877

6978
yield project_id, version_id
7079

appengine/standard_python3/bundled-services/blobstore/flask/main_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ def version():
6565
result = gcloud_cli(f"app deploy --no-promote --version={uuid.uuid4().hex}")
6666
version_id = result["versions"][0]["id"]
6767
project_id = result["versions"][0]["project"]
68+
version_hostname = f"{version_id}-dot-{project_id}.appspot.com"
69+
70+
# Wait for app to initialize
71+
@backoff.on_exception(backoff.expo, requests.exceptions.HTTPError, max_tries=3)
72+
def wait_for_app(url):
73+
r = requests.get(url)
74+
r.raise_for_status()
75+
76+
wait_for_app(f"https://{version_hostname}/")
6877

6978
yield project_id, version_id
7079

appengine/standard_python3/bundled-services/blobstore/wsgi/main_test.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import json
1616
import re
1717
import subprocess
18-
import time
1918
import uuid
2019

2120
import backoff
@@ -66,8 +65,16 @@ def version():
6665
result = gcloud_cli(f"app deploy --no-promote --version={uuid.uuid4().hex}")
6766
version_id = result["versions"][0]["id"]
6867
project_id = result["versions"][0]["project"]
68+
version_hostname = f"{version_id}-dot-{project_id}.appspot.com"
69+
70+
# Wait for app to initialize
71+
@backoff.on_exception(backoff.expo, requests.exceptions.HTTPError, max_tries=3)
72+
def wait_for_app(url):
73+
r = requests.get(url)
74+
r.raise_for_status()
75+
76+
wait_for_app(f"https://{version_hostname}/")
6977

70-
time.sleep(10) # There may be a short delay before responsive
7178
yield project_id, version_id
7279

7380
gcloud_cli(f"app versions delete {version_id}")

appengine/standard_python3/bundled-services/deferred/django/main_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ def version():
6565
result = gcloud_cli(f"app deploy --no-promote --version={uuid.uuid4().hex}")
6666
version_id = result["versions"][0]["id"]
6767
project_id = result["versions"][0]["project"]
68+
version_hostname = f"{version_id}-dot-{project_id}.appspot.com"
69+
70+
# Wait for app to initialize
71+
@backoff.on_exception(backoff.expo, requests.exceptions.HTTPError, max_tries=3)
72+
def wait_for_app(url):
73+
r = requests.get(url)
74+
r.raise_for_status()
75+
76+
wait_for_app(f"https://{version_hostname}/counter/get")
6877

6978
yield project_id, version_id
7079

appengine/standard_python3/bundled-services/deferred/flask/main_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ def version():
6565
result = gcloud_cli(f"app deploy --no-promote --version={uuid.uuid4().hex}")
6666
version_id = result["versions"][0]["id"]
6767
project_id = result["versions"][0]["project"]
68+
version_hostname = f"{version_id}-dot-{project_id}.appspot.com"
69+
70+
# Wait for app to initialize
71+
@backoff.on_exception(backoff.expo, requests.exceptions.HTTPError, max_tries=3)
72+
def wait_for_app(url):
73+
r = requests.get(url)
74+
r.raise_for_status()
75+
76+
wait_for_app(f"https://{version_hostname}/counter/get")
6877

6978
yield project_id, version_id
7079

appengine/standard_python3/bundled-services/deferred/wsgi/main_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ def version():
6565
result = gcloud_cli(f"app deploy --no-promote --version={uuid.uuid4().hex}")
6666
version_id = result["versions"][0]["id"]
6767
project_id = result["versions"][0]["project"]
68+
version_hostname = f"{version_id}-dot-{project_id}.appspot.com"
69+
70+
# Wait for app to initialize
71+
@backoff.on_exception(backoff.expo, requests.exceptions.HTTPError, max_tries=3)
72+
def wait_for_app(url):
73+
r = requests.get(url)
74+
r.raise_for_status()
75+
76+
wait_for_app(f"https://{version_hostname}/counter/get")
6877

6978
yield project_id, version_id
7079

appengine/standard_python3/bundled-services/mail/django/main_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ def version():
6565
result = gcloud_cli(f"app deploy --no-promote --version={uuid.uuid4().hex}")
6666
version_id = result["versions"][0]["id"]
6767
project_id = result["versions"][0]["project"]
68+
version_hostname = f"{version_id}-dot-{project_id}.appspot.com"
69+
70+
# Wait for app to initialize
71+
@backoff.on_exception(backoff.expo, requests.exceptions.HTTPError, max_tries=3)
72+
def wait_for_app(url):
73+
r = requests.get(url)
74+
r.raise_for_status()
75+
76+
wait_for_app(f"https://{version_hostname}/")
6877

6978
yield project_id, version_id
7079

appengine/standard_python3/bundled-services/mail/flask/main_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ def version():
6464
result = gcloud_cli(f"app deploy --no-promote --version={uuid.uuid4().hex}")
6565
version_id = result["versions"][0]["id"]
6666
project_id = result["versions"][0]["project"]
67+
version_hostname = f"{version_id}-dot-{project_id}.appspot.com"
68+
69+
# Wait for app to initialize
70+
@backoff.on_exception(backoff.expo, requests.exceptions.HTTPError, max_tries=3)
71+
def wait_for_app(url):
72+
r = requests.get(url)
73+
r.raise_for_status()
74+
75+
wait_for_app(f"https://{version_hostname}/")
6776

6877
yield project_id, version_id
6978

appengine/standard_python3/bundled-services/mail/wsgi/main_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ def version():
6565
result = gcloud_cli(f"app deploy --no-promote --version={uuid.uuid4().hex}")
6666
version_id = result["versions"][0]["id"]
6767
project_id = result["versions"][0]["project"]
68+
version_hostname = f"{version_id}-dot-{project_id}.appspot.com"
69+
70+
# Wait for app to initialize
71+
@backoff.on_exception(backoff.expo, requests.exceptions.HTTPError, max_tries=3)
72+
def wait_for_app(url):
73+
r = requests.get(url)
74+
r.raise_for_status()
75+
76+
wait_for_app(f"https://{version_hostname}/")
6877

6978
yield project_id, version_id
7079

0 commit comments

Comments
 (0)