Skip to content

Commit 6c3034d

Browse files
author
Jon Wayne Parrott
authored
Update e2e test to be less flaky (GoogleCloudPlatform#104)
1 parent bac4edf commit 6c3034d

4 files changed

Lines changed: 25 additions & 16 deletions

File tree

6-pubsub/tests/test_end_to_end.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
import os
1616
import re
17-
import time
1817

1918
from bs4 import BeautifulSoup
2019
import pytest
2120
import requests
21+
from retrying import retry
2222

2323

2424
@pytest.mark.e2e
@@ -50,10 +50,10 @@ def test_end_to_end():
5050
book_url = response.request.url
5151
book_id = book_url.rsplit('/', 1).pop()
5252

53-
# Wait 30 seconds for pubsub messages to be processed.
54-
time.sleep(30)
55-
56-
try:
53+
# Use retry because it will take some indeterminate time for the pub/sub
54+
# message to be processed.
55+
@retry(wait_exponential_multiplier=1000, stop_max_attempt_number=15)
56+
def check_for_updated_data():
5757
# Check that the book's information was updated.
5858
response = requests.get(book_url)
5959
assert response.status_code == 200
@@ -72,6 +72,9 @@ def test_end_to_end():
7272
image_src = soup.find('img', 'book-image')['src']
7373
image = requests.get(image_src)
7474
assert image.status_code == 200
75+
76+
try:
77+
check_for_updated_data()
7578
finally:
7679
# Delete the book we created.
7780
requests.get(base_url + '/books/{}/delete'.format(book_id))

7-gce/tests/test_end_to_end.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
import os
1616
import re
17-
import time
1817

1918
from bs4 import BeautifulSoup
2019
import pytest
2120
import requests
21+
from retrying import retry
2222

2323

2424
@pytest.mark.e2e
@@ -50,10 +50,10 @@ def test_end_to_end():
5050
book_url = response.request.url
5151
book_id = book_url.rsplit('/', 1).pop()
5252

53-
# Wait 30 seconds for pubsub messages to be processed.
54-
time.sleep(30)
55-
56-
try:
53+
# Use retry because it will take some indeterminate time for the pub/sub
54+
# message to be processed.
55+
@retry(wait_exponential_multiplier=1000, stop_max_attempt_number=15)
56+
def check_for_updated_data():
5757
# Check that the book's information was updated.
5858
response = requests.get(book_url)
5959
assert response.status_code == 200
@@ -72,6 +72,9 @@ def test_end_to_end():
7272
image_src = soup.find('img', 'book-image')['src']
7373
image = requests.get(image_src)
7474
assert image.status_code == 200
75+
76+
try:
77+
check_for_updated_data()
7578
finally:
7679
# Delete the book we created.
7780
requests.get(base_url + '/books/{}/delete'.format(book_id))

nox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'7-gce']
1919

2020

21-
def session_reqcheck(session):
21+
def session_check_requirements(session):
2222
session.install(REPO_TOOLS_REQ)
2323

2424
if 'update' in session.posargs:

optional-container-engine/tests/test_end_to_end.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
import os
1616
import re
17-
import time
1817

1918
from bs4 import BeautifulSoup
2019
import pytest
2120
import requests
21+
from retrying import retry
2222

2323

2424
@pytest.mark.e2e
@@ -50,10 +50,10 @@ def test_end_to_end():
5050
book_url = response.request.url
5151
book_id = book_url.rsplit('/', 1).pop()
5252

53-
# Wait 30 seconds for pubsub messages to be processed.
54-
time.sleep(30)
55-
56-
try:
53+
# Use retry because it will take some indeterminate time for the pub/sub
54+
# message to be processed.
55+
@retry(wait_exponential_multiplier=1000, stop_max_attempt_number=15)
56+
def check_for_updated_data():
5757
# Check that the book's information was updated.
5858
response = requests.get(book_url)
5959
assert response.status_code == 200
@@ -72,6 +72,9 @@ def test_end_to_end():
7272
image_src = soup.find('img', 'book-image')['src']
7373
image = requests.get(image_src)
7474
assert image.status_code == 200
75+
76+
try:
77+
check_for_updated_data()
7578
finally:
7679
# Delete the book we created.
7780
requests.get(base_url + '/books/{}/delete'.format(book_id))

0 commit comments

Comments
 (0)