Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit df0c203

Browse files
committed
Merge pull request #82 from GoogleCloudPlatform/e2e_test
Fixing the test harness to properly refresh test modules.
2 parents 30b6dfc + fc94348 commit df0c203

4 files changed

Lines changed: 36 additions & 12 deletions

File tree

resources/gunicorn.conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@
1717

1818
# Settings specific to the Managed VMs production environment such as "bind"
1919
# and "logfile" are set in the Dockerfile's ENTRYPOINT directive.
20+
21+
# Store the process ID of gunicorn. Used for testing.
22+
pidfile = 'gunicorn_pid.txt'

tests/e2e/app/app.yaml.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ handlers:
55
- url: .*
66
script: main.app
77

8+
manual_scaling:
9+
instances: 1
10+
811
env_variables:
912
CLOUD_STORAGE_BUCKET: $CLOUD_STORAGE_BUCKET

tests/e2e/app/main.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pytest
2020
import os
2121
import shutil
22+
import signal
2223
import sys
2324
import webapp2
2425

@@ -37,21 +38,34 @@ def capture():
3738
finally:
3839
sys.stdout, sys.stderr = oldout, olderr
3940

41+
class RefreshHandler(webapp2.RequestHandler):
4042

41-
class TestRunnerHandler(webapp2.RequestHandler):
42-
43-
def get(self):
44-
# Set up test directory.
45-
if os.path.isdir('tests'):
43+
def get(self):
44+
# Set up test directory.
45+
if os.path.isdir('tests'):
4646
shutil.rmtree('tests')
47-
os.mkdir('tests')
47+
os.mkdir('tests')
4848

49-
# Refresh the tests from cloud storage.
50-
bucket = storage.Client().get_bucket(GCLOUD_STORAGE_BUCKET)
51-
blob_iter = bucket.list_blobs()
52-
for blob in blob_iter:
49+
# Refresh the tests from cloud storage.
50+
bucket = storage.Client().get_bucket(GCLOUD_STORAGE_BUCKET)
51+
blob_iter = bucket.list_blobs()
52+
for blob in blob_iter:
5353
blob.download_to_filename('tests/%s' % blob.name)
5454

55+
# Tell Gunicorn to refresh this process so that our modules
56+
# will be refreshed with the new files. The gunicorn process
57+
# is stored in gunicorn_pid.txt.
58+
with open('gunicorn_pid.txt') as f:
59+
for line in f:
60+
pid = int(line)
61+
62+
os.kill(pid, signal.SIGHUP)
63+
64+
65+
66+
class TestRunnerHandler(webapp2.RequestHandler):
67+
68+
def get(self):
5569
# Run the tests.
5670
with capture() as outf:
5771
result = pytest.main(['tests'])
@@ -62,6 +76,9 @@ def get(self):
6276
self.response.status = 500
6377

6478

79+
80+
6581
app = webapp2.WSGIApplication([
66-
('/', TestRunnerHandler),
82+
('/refresh', RefreshHandler),
83+
('/test', TestRunnerHandler),
6784
], debug=True)

tests/e2e/client/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66

77
def main(url):
8-
response = requests.get(url)
8+
requests.get(url + 'refresh')
9+
response = requests.get(url + 'test')
910

1011
print(response.text)
1112

0 commit comments

Comments
 (0)