Exemplo n.º 1
0
 async def get_address(self, loop: asyncio.AbstractEventLoop) -> SocketAddress:
     server = ThriftServer(Handler(), port=0)
     serve_task = loop.create_task(server.serve())
     addy = await server.get_address()
     server.stop()
     await serve_task
     return addy
Exemplo n.º 2
0
 def __init__(
         self,
         ip: Optional[str] = None,
         path: Optional["Path"] = None,
         handler: ServiceInterface = Handler(),  # noqa: B008
 ) -> None:
     self.server = ThriftServer(handler, ip=ip, path=path)
Exemplo n.º 3
0
    def test_server_get_stats(self) -> None:
        # pyre-fixme[45]: Cannot instantiate abstract class `Handler`.
        server = ThriftServer(Handler(), port=0)

        active_requests = server.get_active_requests()
        self.assertGreaterEqual(active_requests, 0)
        self.assertLess(active_requests, 10)
Exemplo n.º 4
0
async def server_in_event_loop() -> typing.AsyncGenerator[SocketAddress, None]:
    server = ThriftServer(LeafServiceHandler(), ip="::1")
    serve_task = asyncio.get_event_loop().create_task(server.serve())
    addr = await server.get_address()
    try:
        yield addr
    finally:
        server.stop()
        await serve_task
Exemplo n.º 5
0
 async def get_address(self,
                       loop: asyncio.AbstractEventLoop) -> SocketAddress:
     # pyre-fixme[45]: Cannot instantiate abstract class `Handler`.
     server = ThriftServer(Handler(), port=0)
     serve_task = loop.create_task(server.serve())
     addy = await server.get_address()
     server.stop()
     await serve_task
     return addy
Exemplo n.º 6
0
async def server_in_event_loop():
    server = ThriftServer(Handler(), ip="::1")
    serve_task = asyncio.get_event_loop().create_task(server.serve())
    addr = await server.get_address()
    try:
        yield addr
    finally:
        server.stop()
        await serve_task
Exemplo n.º 7
0
 async def inner() -> None:
     # pyre-fixme[45]: Cannot instantiate abstract class `Handler`.
     handler = Handler()
     self.assertFalse(handler.on_start_serving_called)
     self.assertFalse(handler.on_stop_requested_called)
     server = ThriftServer(handler, port=0)
     serve_task = asyncio.get_event_loop().create_task(server.serve())
     await server.get_address()
     self.assertTrue(handler.on_start_serving_called)
     server.stop()
     await serve_task
     self.assertTrue(handler.on_stop_requested_called)
Exemplo n.º 8
0
def main():
    parser = ArgumentParser()
    parser.add_argument('--port',
                        default=1234,
                        type=int,
                        help='Port to run on')
    options = parser.parse_args()
    loop = asyncio.get_event_loop()
    handler = LoadTestHandler(loop)
    server = ThriftServer(handler, options.port, loop=loop)
    loop.add_signal_handler(signal.SIGINT, server.stop)
    loop.add_signal_handler(signal.SIGTERM, server.stop)
    print("Running Py3 server on port {}".format(options.port))
    loop.run_until_complete(server.serve())
Exemplo n.º 9
0
class TestServer:
    server: ThriftServer
    serve_task: asyncio.Task

    def __init__(self, *, ip: str, handler: thrift.py3.server.ServiceInterface) -> None:
        self.server = ThriftServer(handler, ip=ip, path=None)

    async def __aenter__(self) -> thrift.py3.server.SocketAddress:
        self.serve_task = asyncio.get_event_loop().create_task(self.server.serve())
        return await self.server.get_address()

    # pyre-fixme[2]: Parameter must be annotated.
    async def __aexit__(self, *exc_info) -> None:
        self.server.stop()
        await self.serve_task
Exemplo n.º 10
0
class TestServer:
    server: ThriftServer
    serve_task: asyncio.Task

    def __init__(
            self,
            ip: Optional[str] = None,
            handler: ServiceInterface = Handler(),  # noqa: B008
    ) -> None:
        self.server = ThriftServer(handler, ip=ip)

    async def __aenter__(self) -> SocketAddress:
        self.serve_task = asyncio.get_event_loop().create_task(
            self.server.serve())
        return await self.server.get_address()

    # pyre-fixme[2]: Parameter must be annotated.
    async def __aexit__(self, *exc_info) -> None:
        self.server.stop()
        await self.serve_task
Exemplo n.º 11
0
 async def start_server_async(path: str) -> None:
     server = ThriftServer(LeafServiceHandler(), path=path)
     await server.serve()
Exemplo n.º 12
0
 def __init__(self, *, ip: str,
              handler: thrift.py3.server.ServiceInterface) -> None:
     self.server = ThriftServer(handler, ip=ip, path=None)
Exemplo n.º 13
0
    def test_server_manipulate_config(self) -> None:
        MAX_REQUESTS = 142
        MAX_CONNECTIONS = 132
        LISTEN_BACKLOG = 167
        NUM_IO_WORKERS = 10
        IDLE_TIMEOUT = 19.84
        QUEUE_TIMEOUT = 20.19

        # pyre-fixme[45]: Cannot instantiate abstract class `Handler`.
        server = ThriftServer(Handler(), port=0)
        server.set_max_requests(MAX_REQUESTS)
        server.set_max_connections(MAX_CONNECTIONS)
        server.set_listen_backlog(LISTEN_BACKLOG)
        server.set_io_worker_threads(NUM_IO_WORKERS)
        server.set_idle_timeout(IDLE_TIMEOUT)
        server.set_queue_timeout(QUEUE_TIMEOUT)
        self.assertEqual(server.get_max_requests(), MAX_REQUESTS)
        self.assertEqual(server.get_max_connections(), MAX_CONNECTIONS)
        self.assertEqual(server.get_listen_backlog(), LISTEN_BACKLOG)
        self.assertEqual(server.get_io_worker_threads(), NUM_IO_WORKERS)
        self.assertEqual(server.get_idle_timeout(), IDLE_TIMEOUT)
        self.assertEqual(server.get_queue_timeout(), QUEUE_TIMEOUT)

        self.assertFalse(server.is_plaintext_allowed_on_loopback())
        server.set_allow_plaintext_on_loopback(True)
        self.assertTrue(server.is_plaintext_allowed_on_loopback())
Exemplo n.º 14
0
    def test_server_get_stats(self) -> None:
        server = ThriftServer(Handler(), port=0)

        active_requests = server.get_active_requests()
        self.assertGreaterEqual(active_requests, 0)
        self.assertLess(active_requests, 10)
Exemplo n.º 15
0
    def test_server_manipulate_config(self) -> None:
        MAX_REQUESTS = 142
        MAX_CONNECTIONS = 132
        LISTEN_BACKLOG = 167
        NUM_IO_WORKERS = 10
        NUM_CPU_WORKERS = 42
        NUM_SSL_WORKERS = 12
        IDLE_TIMEOUT = 19.84
        QUEUE_TIMEOUT = 20.19

        server = ThriftServer(Handler(), port=0)
        server.set_max_requests(MAX_REQUESTS)
        server.set_max_connections(MAX_CONNECTIONS)
        server.set_listen_backlog(LISTEN_BACKLOG)
        server.set_io_worker_threads(NUM_IO_WORKERS)
        server.set_cpu_worker_threads(NUM_CPU_WORKERS)
        server.set_ssl_handshake_worker_threads(NUM_SSL_WORKERS)
        server.set_idle_timeout(IDLE_TIMEOUT)
        server.set_queue_timeout(QUEUE_TIMEOUT)
        self.assertEqual(server.get_max_requests(), MAX_REQUESTS)
        self.assertEqual(server.get_max_connections(), MAX_CONNECTIONS)
        self.assertEqual(server.get_listen_backlog(), LISTEN_BACKLOG)
        self.assertEqual(server.get_io_worker_threads(), NUM_IO_WORKERS)
        self.assertEqual(server.get_cpu_worker_threads(), NUM_CPU_WORKERS)
        self.assertEqual(server.get_ssl_handshake_worker_threads(),
                         NUM_SSL_WORKERS)
        self.assertEqual(server.get_idle_timeout(), IDLE_TIMEOUT)
        self.assertEqual(server.get_queue_timeout(), QUEUE_TIMEOUT)

        self.assertFalse(server.is_plaintext_allowed_on_loopback())
        server.set_allow_plaintext_on_loopback(True)
        self.assertTrue(server.is_plaintext_allowed_on_loopback())
Exemplo n.º 16
0
 async def start_server_async(path):
     server = ThriftServer(Handler(), path=path)
     await server.serve()