def test_ping(self): application = Application() with ManagedServerLoop(application, keep_alive_milliseconds=0) as server: session = ClientSession(session_id='test_ping', websocket_url=ws_url(server), io_loop=server.io_loop) session.connect() assert session.connected assert session.document is None connection = next(iter(server._tornado._clients)) expected_pong = connection._ping_count server._tornado.keep_alive() # send ping session.force_roundtrip() self.assertEqual(expected_pong, connection._socket.latest_pong) # check that each ping increments by 1 server._tornado.keep_alive() session.force_roundtrip() self.assertEqual(expected_pong + 1, connection._socket.latest_pong) session.close() session.loop_until_closed() assert not session.connected
def test_ping(self): application = Application() with ManagedServerLoop(application, keep_alive_milliseconds=0) as server: session = ClientSession(session_id='test_ping', websocket_url=ws_url(server), io_loop=server.io_loop) session.connect() assert session.connected assert session.document is None connection = next(iter(server._tornado._clients)) expected_pong = connection._ping_count server._tornado._keep_alive() # send ping session.force_roundtrip() assert expected_pong == connection._socket.latest_pong # check that each ping increments by 1 server._tornado._keep_alive() session.force_roundtrip() assert (expected_pong + 1) == connection._socket.latest_pong session.close() session.loop_until_closed(suppress_warning=True) assert not session.connected
def test_minimal_connect_and_disconnect(self): application = Application() with ManagedServerLoop(application) as server: # we don't have to start the server because it # uses the same main loop as the client, so # if we start either one it starts both session = ClientSession(io_loop = server.io_loop, url = ws_url(server)) session.connect() assert session.connected
def test_minimal_connect_and_disconnect(self, ManagedServerLoop) -> None: application = Application() with ManagedServerLoop(application) as server: # we don't have to start the server because it # uses the same main loop as the client, so # if we start either one it starts both session = ClientSession(session_id='test_minimal_connect_and_disconnect', io_loop = server.io_loop, websocket_url = ws_url(server)) session.connect() assert session.connected
def test_disconnect_on_error(self): application = Application() with ManagedServerLoop(application) as server: session = ClientSession(url=server.ws_url, io_loop=server.io_loop) session.connect() assert session.connected # send a bogus message using private fields session._connection._socket.write_message(b"xx", binary=True) # connection should now close on the server side # and the client loop should end session.loop_until_closed() assert not session.connected
def test_minimal_connect_and_disconnect(self): application = Application() with ManagedServerLoop(application) as server: # we don't have to start the server because it # uses the same main loop as the client, so # if we start either one it starts both session = ClientSession(io_loop=server.io_loop, url=server.ws_url) session.connect() assert session.connected session.close() session.loop_until_closed() assert not session.connected
def test_disconnect_on_error(self): application = Application() with ManagedServerLoop(application) as server: session = ClientSession(url=server.ws_url, io_loop = server.io_loop) session.connect() assert session.connected # send a bogus message using private fields session._connection._socket.write_message(b"xx", binary=True) # connection should now close on the server side # and the client loop should end session.loop_until_closed() assert not session.connected
def test_host_whitelist_success(self): application = Application() # succeed no host value with defaults with ManagedServerLoop(application, host=None) as server: session = ClientSession(websocket_url=ws_url(server), io_loop = server.io_loop) session.connect() assert session.connected session.close() session.loop_until_closed() # succeed no host value with port with ManagedServerLoop(application, port=8080, host=None) as server: session = ClientSession(websocket_url=ws_url(server), io_loop = server.io_loop) session.connect() assert session.connected session.close() session.loop_until_closed() # succeed matching host value with ManagedServerLoop(application, port=8080, host=["localhost:8080"]) as server: session = ClientSession(websocket_url=ws_url(server), io_loop = server.io_loop) session.connect() assert session.connected session.close() session.loop_until_closed() # succeed matching host value one of multiple with ManagedServerLoop(application, port=8080, host=["bad_host", "localhost:8080"]) as server: session = ClientSession(websocket_url=ws_url(server), io_loop = server.io_loop) session.connect() assert session.connected session.close() session.loop_until_closed()
def test_host_whitelist_success(self): application = Application() # succeed no host value with defaults with ManagedServerLoop(application, host=None) as server: session = ClientSession(url=ws_url(server), io_loop = server.io_loop) session.connect() assert session.connected session.close() session.loop_until_closed() # succeed no host value with port with ManagedServerLoop(application, port=8080, host=None) as server: session = ClientSession(url=ws_url(server), io_loop = server.io_loop) session.connect() assert session.connected session.close() session.loop_until_closed() # succeed matching host value with ManagedServerLoop(application, port=8080, host=["localhost:8080"]) as server: session = ClientSession(url=ws_url(server), io_loop = server.io_loop) session.connect() assert session.connected session.close() session.loop_until_closed() # succeed matching host value one of multiple with ManagedServerLoop(application, port=8080, host=["bad_host", "localhost:8080"]) as server: session = ClientSession(url=ws_url(server), io_loop = server.io_loop) session.connect() assert session.connected session.close() session.loop_until_closed()
def test_host_whitelist_failure(self): application = Application() # failure bad host with ManagedServerLoop(application, host=["bad_host"]) as server: session = ClientSession(websocket_url=ws_url(server), io_loop=server.io_loop) session.connect() assert not session.connected session.close() session.loop_until_closed() with ManagedServerLoop(application, host=["bad_host:5006"]) as server: session = ClientSession(websocket_url=ws_url(server), io_loop=server.io_loop) session.connect() assert not session.connected session.close() session.loop_until_closed() # failure good host, bad port with ManagedServerLoop(application, host=["localhost:80"]) as server: session = ClientSession(websocket_url=ws_url(server), io_loop=server.io_loop) session.connect() assert not session.connected session.close() session.loop_until_closed() # failure good host, bad default port with ManagedServerLoop(application, host=["localhost"]) as server: session = ClientSession(websocket_url=ws_url(server), io_loop=server.io_loop) session.connect() assert not session.connected session.close() session.loop_until_closed() # failure with custom port with ManagedServerLoop(application, port=8080, host=["localhost:8081"]) as server: session = ClientSession(websocket_url=ws_url(server), io_loop=server.io_loop) session.connect() assert not session.connected session.close() session.loop_until_closed()
def test_disconnect_on_error(self, ManagedServerLoop) -> None: application = Application() with ManagedServerLoop(application) as server: session = ClientSession(session_id='test_disconnect_on_error', websocket_url=ws_url(server), io_loop = server.io_loop) session.connect() assert session.connected # send a bogus message using private fields server.io_loop.spawn_callback(session._connection._socket.write_message, b"xx", binary=True) # connection should now close on the server side # and the client loop should end session._loop_until_closed() assert not session.connected session.close() session._loop_until_closed() assert not session.connected
def test_request_server_info(self): application = Application() with ManagedServerLoop(application) as server: session = ClientSession(url=server.ws_url, io_loop=server.io_loop) session.connect() assert session.connected assert session.document is None info = session.request_server_info() from bokeh import __version__ assert info['version_info']['bokeh'] == __version__ assert info['version_info']['server'] == __version__ session.close() session.loop_until_closed() assert not session.connected
def test_connect_with_prefix(self): application = Application() with ManagedServerLoop(application, prefix="foo") as server: # we don't have to start the server because it # uses the same main loop as the client, so # if we start either one it starts both session = ClientSession(io_loop=server.io_loop, websocket_url=ws_url(server, "/foo")) session.connect() assert session.connected session.close() session.loop_until_closed(suppress_warning=True) session = ClientSession(io_loop=server.io_loop, websocket_url=ws_url(server)) session.connect() assert not session.connected session.close() session.loop_until_closed(suppress_warning=True)
def test_connect_with_prefix(self): application = Application() with ManagedServerLoop(application, prefix="foo") as server: # we don't have to start the server because it # uses the same main loop as the client, so # if we start either one it starts both session = ClientSession(io_loop = server.io_loop, websocket_url = ws_url(server, "/foo")) session.connect() assert session.connected session.close() session.loop_until_closed() session = ClientSession(io_loop = server.io_loop, websocket_url = ws_url(server)) session.connect() assert not session.connected session.close() session.loop_until_closed()
def test_request_server_info(self): application = Application() with ManagedServerLoop(application) as server: session = ClientSession(session_id='test_request_server_info', websocket_url=ws_url(server), io_loop=server.io_loop) session.connect() assert session.connected assert session.document is None info = session.request_server_info() from bokeh import __version__ assert info['version_info']['bokeh'] == __version__ assert info['version_info']['server'] == __version__ session.close() session.loop_until_closed(suppress_warning=True) assert not session.connected
def test_request_server_info(self, ManagedServerLoop: MSL) -> None: application = Application() with ManagedServerLoop(application) as server: session = ClientSession(session_id=ID("test_request_server_info"), websocket_url=ws_url(server), io_loop=server.io_loop) session.connect() assert session.connected assert session.document is None info = session.request_server_info() from bokeh import __version__ assert info['version_info']['bokeh'] == __version__ assert info['version_info']['server'] == __version__ session.close() session._loop_until_closed() assert not session.connected
def test_host_whitelist_failure(self): application = Application() # failure bad host with ManagedServerLoop(application, host=["bad_host"]) as server: session = ClientSession(url=ws_url(server), io_loop = server.io_loop) session.connect() assert not session.connected session.close() session.loop_until_closed() with ManagedServerLoop(application, host=["bad_host:5006"]) as server: session = ClientSession(url=ws_url(server), io_loop = server.io_loop) session.connect() assert not session.connected session.close() session.loop_until_closed() # failure good host, bad port with ManagedServerLoop(application, host=["localhost:80"]) as server: session = ClientSession(url=ws_url(server), io_loop = server.io_loop) session.connect() assert not session.connected session.close() session.loop_until_closed() # failure good host, bad default port with ManagedServerLoop(application, host=["localhost"]) as server: session = ClientSession(url=ws_url(server), io_loop = server.io_loop) session.connect() assert not session.connected session.close() session.loop_until_closed() # failure with custom port with ManagedServerLoop(application, port=8080, host=["localhost:8081"]) as server: session = ClientSession(url=ws_url(server), io_loop = server.io_loop) session.connect() assert not session.connected session.close() session.loop_until_closed()