From 8c7882c5e7c67e6bb4c40bac6e07328de9018795 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Tue, 24 Jan 2017 14:13:40 +0900 Subject: [PATCH] sanic_endpoint_test uses shared event loop by default --- sanic/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sanic/utils.py b/sanic/utils.py index 1eaa0493..0ea2f09e 100644 --- a/sanic/utils.py +++ b/sanic/utils.py @@ -5,6 +5,13 @@ HOST = '127.0.0.1' PORT = 42101 +try: + import uvloop as async_loop +except ImportError: + import asyncio as async_loop +endpoint_test_loop = async_loop.new_event_loop() + + async def local_request(method, uri, cookies=None, *args, **kwargs): url = 'http://{host}:{port}{uri}'.format(host=HOST, port=PORT, uri=uri) log.info(url) @@ -16,7 +23,7 @@ async def local_request(method, uri, cookies=None, *args, **kwargs): def sanic_endpoint_test(app, method='get', uri='/', gather_request=True, - loop=None, debug=False, server_kwargs={}, + loop=endpoint_test_loop, debug=False, server_kwargs={}, *request_args, **request_kwargs): results = [] exceptions = []