async def test_server_close(app, make_manager, make_request): reached_closed = False loop = asyncio.get_event_loop() async def handler(msg, session): nonlocal reached_closed if msg.tp == MSG_OPEN: asyncio.ensure_future(session._remote_message("TESTMSG")) pass elif msg.tp == MSG_MESSAGE: # To reproduce the ordering which makes the issue loop.call_later(0.05, session.close) elif msg.tp == MSG_CLOSED: reached_closed = True app.freeze() request = make_request("GET", "/", query_params={}) manager = SessionManager("sm", app, handler, debug=True) session = manager.get("test", create=True) transp = WebSocketTransport(manager, session, request) await transp.process() assert reached_closed is True
async def test_server_close(app, make_manager, make_request): reached_closed = False loop = asyncio.get_event_loop() async def handler(msg, session): nonlocal reached_closed if msg.tp == MSG_OPEN: asyncio.ensure_future(session._remote_message("TESTMSG"), loop=loop) pass elif msg.tp == MSG_MESSAGE: # To reproduce the ordering which makes the issue loop.call_later(0.05, session.close) elif msg.tp == MSG_CLOSED: reached_closed = True app.freeze() request = make_request("GET", "/", query_params={}, loop=loop) manager = SessionManager("sm", app, handler, loop=loop, debug=True) session = manager.get("test", create=True) transp = WebSocketTransport(manager, session, request) await transp.process() assert reached_closed is True
def test_server_close(app, loop, make_manager, make_request): # Issue #161 reached_closed = False @asyncio.coroutine def handler(msg, session): nonlocal reached_closed if msg.tp == MSG_OPEN: asyncio.ensure_future(session._remote_message('TESTMSG'), loop=loop) pass elif msg.tp == MSG_MESSAGE: # To reproduce the ordering which makes the issue loop.call_later(0.05, session.close) elif msg.tp == MSG_CLOSED: reached_closed = True request = make_request('GET', '/', query_params={}) manager = SessionManager('sm', app, handler, loop=loop, debug=True) session = manager.get('test', create=True) transp = WebSocketTransport(manager, session, request) resp = yield from transp.process() assert reached_closed