This repository has been archived by the owner on Dec 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcc019e
commit f6b5160
Showing
10 changed files
with
152 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""We want to ensure that users can run Texrrow through UWSGI without issues. | ||
This script is ran by Travis and AppVeyor to ensure the compatibility. | ||
This is a heavy test and incompatible test with pytest. | ||
Thus we keep it separated from the rest of the tests.""" | ||
import os | ||
import signal | ||
import sys | ||
import time | ||
|
||
import mock | ||
import requests | ||
import requests.exceptions | ||
|
||
from texrrow import __main__ as main | ||
|
||
TEST_PORT = 12345 | ||
|
||
|
||
def _knock_url_and_wait(url, timeout_per_request=1, global_timeout=10): | ||
status = None | ||
end_time = time.time() + global_timeout | ||
while status is None: | ||
try: | ||
response = requests.head(url, timeout=timeout_per_request) | ||
status = response.status_code | ||
except requests.exceptions.ConnectionError: # noqa | ||
if time.time() > end_time: | ||
raise | ||
assert status == 200 | ||
|
||
|
||
def _run_and_test(to_run): | ||
child_pid = os.fork() | ||
if child_pid == 0: | ||
to_run() | ||
sys.exit(0) | ||
try: | ||
test_url = 'http://127.0.0.1:%d' % TEST_PORT | ||
time.sleep(0.1) | ||
pid, status = os.waitpid(child_pid, os.P_NOWAIT) | ||
|
||
# ensure the process did not exit | ||
assert not os.WEXITSTATUS(pid) | ||
|
||
# try to ping uwsgi and get a HTTP 200 | ||
_knock_url_and_wait(test_url) | ||
finally: | ||
os.kill(child_pid, signal.SIGTERM) | ||
os.wait() | ||
|
||
|
||
@mock.patch.object(main, 'PORT', new=TEST_PORT) | ||
def test_start_servers(): | ||
_run_and_test(main.start_uwsgi) | ||
_run_and_test(main.start_flask) | ||
|
||
|
||
if __name__ == '__main__': | ||
test_start_servers() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ omit = | |
*/test_*.py | ||
tests/*.py | ||
*/commands/populatedb.py | ||
*/__main__.py | ||
.ci/* | ||
*/wsgi* | ||
source = texrrow | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,24 @@ | ||
def main(): | ||
import os | ||
import os.path | ||
import sys | ||
|
||
PORT = 5000 | ||
UWSGI_PATH = os.path.realpath(os.path.join(sys.executable, os.pardir, 'uwsgi')) | ||
|
||
|
||
def _get_port_from_argv(): | ||
if len(sys.argv) > 1: | ||
port = int(sys.argv[1]) | ||
return port | ||
return PORT | ||
|
||
|
||
def start_flask(): | ||
from .application import create_app | ||
create_app().run() | ||
create_app().run(host='0.0.0.0', port=_get_port_from_argv(), debug=False) | ||
|
||
|
||
def start_uwsgi(): | ||
port = ':%d' % _get_port_from_argv() | ||
argv = ['uwsgi', '--http', port, '--module', 'texrrow.wsgi:application'] | ||
os.execve(UWSGI_PATH, argv, os.environ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from texrrow.application import create_app | ||
|
||
|
||
def health_check(_application, health_url): | ||
def health_check_wrapper(environ, start_response): | ||
if environ.get('PATH_INFO') == health_url: | ||
start_response('200 OK', [('Content-Type', 'text/plain')]) | ||
return [] | ||
return _application(environ, start_response) | ||
return health_check_wrapper | ||
|
||
|
||
application = health_check(create_app(), '/health/') |