Add a simple integration test for Gunicorn worker

This commit is contained in:
messense 2017-05-23 10:59:55 +08:00
parent b447807b36
commit 3eed81c1eb
No known key found for this signature in database
GPG Key ID: BB41A8A2C716CCA9
3 changed files with 24 additions and 0 deletions

View File

@ -9,3 +9,4 @@ pytest
tox tox
ujson ujson
uvloop uvloop
gunicorn

22
tests/test_worker.py Normal file
View File

@ -0,0 +1,22 @@
import time
import json
import shlex
import subprocess
import urllib.request
import pytest
@pytest.fixture(scope='module')
def gunicorn_worker():
command = 'gunicorn --bind 127.0.0.1:1337 --worker-class sanic.worker.GunicornWorker examples.simple_server:app'
worker = subprocess.Popen(shlex.split(command))
time.sleep(1)
yield
worker.kill()
def test_gunicorn_worker(gunicorn_worker):
with urllib.request.urlopen('http://localhost:1337/') as f:
res = json.loads(f.read(100).decode())
assert res['test']

View File

@ -13,6 +13,7 @@ deps =
aiohttp==1.3.5 aiohttp==1.3.5
chardet<=2.3.0 chardet<=2.3.0
beautifulsoup4 beautifulsoup4
gunicorn
commands = commands =
pytest tests {posargs} pytest tests {posargs}
coverage erase coverage erase