stop multiple worker server without sleep loop; issue #73

This commit is contained in:
Raphael Deem
2016-12-26 14:37:05 -08:00
parent f74d44152a
commit a4f77984b7
2 changed files with 27 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
from multiprocessing import Array, Event, Process
from time import sleep
from time import sleep, time
from ujson import loads as json_loads
from sanic import Sanic
@@ -51,3 +51,27 @@ def skip_test_multiprocessing():
raise ValueError("Expected JSON response but got '{}'".format(response))
assert results.get('test') == True
def test_drain_connections():
app = Sanic('test_json')
@app.route('/')
async def handler(request):
return json({"test": True})
stop_event = Event()
async def after_start(*args, **kwargs):
http_response = await local_request('get', '/')
stop_event.set()
start = time()
app.serve_multiple({
'host': HOST,
'port': PORT,
'after_start': after_start,
'request_handler': app.handle_request,
}, workers=2, stop_event=stop_event)
end = time()
assert end - start < 0.05