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 make_manager(self, handler=None): if handler is None: handler = self.make_handler([]) s = self.make_session('test', handler=handler) return s, SessionManager('sm', self.app, handler, loop=self.loop, debug=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
def maker(handlers=transports.handlers): handler = make_handler([]) sm = SessionManager('sm', app, handler, loop=loop) return SockJSRoute('sm', sm, 'http:sockjs-cdn', handlers, (), True)
def maker(handler=None): if handler is None: handler = make_handler([]) s = make_session('test', handler=handler) return s, SessionManager('sm', app, handler, loop=loop, debug=True)
def maker(handlers=transports.handlers): handler = make_handler([]) sm = SessionManager("sm", app, handler) return SockJSRoute("sm", sm, "http:sockjs-cdn", handlers, (), True)
def maker(handler=None): if handler is None: handler = make_handler([]) return SessionManager("sm", app, handler, debug=True)
def maker(handler=None): if handler is None: handler = make_handler([]) return SessionManager('sm', app, handler, loop=loop, debug=True)