worker
This commit is contained in:
parent
64f0496d9e
commit
5f17e9591b
|
@ -32,7 +32,6 @@ class ExceptionMixin:
|
|||
if isinstance(exceptions[0], list):
|
||||
exceptions = tuple(*exceptions)
|
||||
|
||||
print(handler, exceptions)
|
||||
future_exception = FutureException(handler, exceptions)
|
||||
self._future_exceptions.add(future_exception)
|
||||
if apply:
|
||||
|
|
|
@ -42,12 +42,6 @@ class Router(BaseRouter):
|
|||
except RoutingNotFound as e:
|
||||
raise NotFound("Requested URL {} not found".format(e.path))
|
||||
except NoMethod as e:
|
||||
print(
|
||||
"Method {} not allowed for URL {}".format(
|
||||
request.method, request.path
|
||||
),
|
||||
e.allowed_methods,
|
||||
)
|
||||
raise MethodNotSupported(
|
||||
"Method {} not allowed for URL {}".format(
|
||||
request.method, request.path
|
||||
|
|
|
@ -137,7 +137,6 @@ class GunicornWorker(base.Worker):
|
|||
await _shutdown
|
||||
|
||||
async def _run(self):
|
||||
self.app.router.finalize()
|
||||
for sock in self.sockets:
|
||||
state = dict(requests_count=0)
|
||||
self._server_settings["host"] = None
|
||||
|
|
|
@ -69,9 +69,11 @@ def handler(request):
|
|||
def test_pickle_app(app, protocol):
|
||||
app.route("/")(handler)
|
||||
app.router.finalize()
|
||||
app.router.reset()
|
||||
p_app = pickle.dumps(app, protocol=protocol)
|
||||
del app
|
||||
up_p_app = pickle.loads(p_app)
|
||||
up_p_app.router.finalize()
|
||||
assert up_p_app
|
||||
request, response = up_p_app.test_client.get("/")
|
||||
assert response.text == "Hello"
|
||||
|
@ -82,9 +84,12 @@ def test_pickle_app_with_bp(app, protocol):
|
|||
bp = Blueprint("test_text")
|
||||
bp.route("/")(handler)
|
||||
app.blueprint(bp)
|
||||
app.router.finalize()
|
||||
app.router.reset()
|
||||
p_app = pickle.dumps(app, protocol=protocol)
|
||||
del app
|
||||
up_p_app = pickle.loads(p_app)
|
||||
up_p_app.router.finalize()
|
||||
assert up_p_app
|
||||
request, response = up_p_app.test_client.get("/")
|
||||
assert response.text == "Hello"
|
||||
|
@ -94,9 +99,12 @@ def test_pickle_app_with_bp(app, protocol):
|
|||
def test_pickle_app_with_static(app, protocol):
|
||||
app.route("/")(handler)
|
||||
app.static("/static", "/tmp/static")
|
||||
app.router.finalize()
|
||||
app.router.reset()
|
||||
p_app = pickle.dumps(app, protocol=protocol)
|
||||
del app
|
||||
up_p_app = pickle.loads(p_app)
|
||||
up_p_app.router.finalize()
|
||||
assert up_p_app
|
||||
request, response = up_p_app.test_client.get("/static/missing.txt")
|
||||
assert response.status == 404
|
||||
|
|
|
@ -9,6 +9,8 @@ from unittest import mock
|
|||
|
||||
import pytest
|
||||
|
||||
from sanic_testing.testing import ASGI_PORT as PORT
|
||||
|
||||
from sanic.app import Sanic
|
||||
from sanic.worker import GunicornWorker
|
||||
|
||||
|
@ -17,7 +19,7 @@ from sanic.worker import GunicornWorker
|
|||
def gunicorn_worker():
|
||||
command = (
|
||||
"gunicorn "
|
||||
"--bind 127.0.0.1:1337 "
|
||||
f"--bind 127.0.0.1:{PORT} "
|
||||
"--worker-class sanic.worker.GunicornWorker "
|
||||
"examples.simple_server:app"
|
||||
)
|
||||
|
@ -31,7 +33,7 @@ def gunicorn_worker():
|
|||
def gunicorn_worker_with_access_logs():
|
||||
command = (
|
||||
"gunicorn "
|
||||
"--bind 127.0.0.1:1338 "
|
||||
f"--bind 127.0.0.1:{PORT + 1} "
|
||||
"--worker-class sanic.worker.GunicornWorker "
|
||||
"examples.simple_server:app"
|
||||
)
|
||||
|
@ -45,7 +47,7 @@ def gunicorn_worker_with_env_var():
|
|||
command = (
|
||||
'env SANIC_ACCESS_LOG="False" '
|
||||
"gunicorn "
|
||||
"--bind 127.0.0.1:1339 "
|
||||
f"--bind 127.0.0.1:{PORT + 2} "
|
||||
"--worker-class sanic.worker.GunicornWorker "
|
||||
"--log-level info "
|
||||
"examples.simple_server:app"
|
||||
|
@ -56,7 +58,7 @@ def gunicorn_worker_with_env_var():
|
|||
|
||||
|
||||
def test_gunicorn_worker(gunicorn_worker):
|
||||
with urllib.request.urlopen("http://localhost:1337/") as f:
|
||||
with urllib.request.urlopen(f"http://localhost:{PORT}/") as f:
|
||||
res = json.loads(f.read(100).decode())
|
||||
assert res["test"]
|
||||
|
||||
|
@ -65,7 +67,7 @@ def test_gunicorn_worker_no_logs(gunicorn_worker_with_env_var):
|
|||
"""
|
||||
if SANIC_ACCESS_LOG was set to False do not show access logs
|
||||
"""
|
||||
with urllib.request.urlopen("http://localhost:1339/") as _:
|
||||
with urllib.request.urlopen(f"http://localhost:{PORT + 2}/") as _:
|
||||
gunicorn_worker_with_env_var.kill()
|
||||
assert not gunicorn_worker_with_env_var.stdout.read()
|
||||
|
||||
|
@ -74,7 +76,7 @@ def test_gunicorn_worker_with_logs(gunicorn_worker_with_access_logs):
|
|||
"""
|
||||
default - show access logs
|
||||
"""
|
||||
with urllib.request.urlopen("http://localhost:1338/") as _:
|
||||
with urllib.request.urlopen(f"http://localhost:{PORT + 1}/") as _:
|
||||
gunicorn_worker_with_access_logs.kill()
|
||||
assert (
|
||||
b"(sanic.access)[INFO][127.0.0.1"
|
||||
|
|
Loading…
Reference in New Issue
Block a user