From 9de0e341e96fc86ced7e7549fc50755c378d0a9c Mon Sep 17 00:00:00 2001 From: prryplatypus <25409753+prryplatypus@users.noreply.github.com> Date: Mon, 1 Nov 2021 19:57:50 +0100 Subject: [PATCH] Split create_server tests so loop isn't closed prematurely --- tests/test_app.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/test_app.py b/tests/test_app.py index 04f63ca0..18d06b9c 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -455,16 +455,29 @@ def test_uvloop_usage(app, monkeypatch): app.test_client.get("/test") use_uvloop.assert_called_once() - # Try with create_server - use_uvloop.reset_mock() + +def test_uvloop_usage_with_create_server(app, monkeypatch): + @app.get("/test") + def handler(request): + return text("ok") + + use_uvloop = Mock() + monkeypatch.setattr(sanic.app, "use_uvloop", use_uvloop) + loop = asyncio.get_event_loop() app.config["USE_UVLOOP"] = False - asyncio_srv_coro = app.create_server(return_asyncio_server=True) + asyncio_srv_coro = app.create_server( + return_asyncio_server=True, + asyncio_server_kwargs=dict(start_serving=False) + ) loop.run_until_complete(asyncio_srv_coro) use_uvloop.assert_not_called() app.config["USE_UVLOOP"] = True - asyncio_srv_coro = app.create_server(return_asyncio_server=True) + asyncio_srv_coro = app.create_server( + return_asyncio_server=True, + asyncio_server_kwargs=dict(start_serving=False) + ) loop.run_until_complete(asyncio_srv_coro) use_uvloop.assert_called_once()