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
async def async_main(port):
    loop = asyncio.get_event_loop()
    server = ThriftServer(EchoHandler(), port=port)
    serve_task = loop.create_task(server.serve())
    for signal in [SIGINT, SIGTERM]:
        loop.add_signal_handler(signal, server.stop)
    addr = await server.get_address()
    print(f"Listening on {addr}")
    await serve_task
Exemplo n.º 4
0
async def main():
    server = ThriftServer(Handler())
    serve_task = asyncio.create_task(server.serve())
    addr = await server.get_address()
    print(addr.port, flush=True)
    print("\n", flush=True)
    try:
        await serve_task
    finally:
        server.stop()
Exemplo n.º 5
0
class TestServer:
    server: ThriftServer
    serve_task: asyncio.Task

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

    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.º 6
0
 def __init__(self, *, ip: str, handler: ServiceInterface) -> None:
     self.server = ThriftServer(handler, ip=ip, path=None)
Exemplo n.º 7
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.º 8
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

        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())