async def inner_test() -> None: async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client(TestingService, host=ip, port=port) as client: self.assertEqual(True, await client.renamed_func(True))
async def inner_test() -> None: async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client(TestingService, host=ip, port=port) as client: self.assertTrue(await client.invert(False)) self.assertFalse(await client.invert(True))
def init_client(self) -> Calculator: return get_client( Calculator, port=self.interaction.getPort(), host="::1", client_type=ClientType.THRIFT_ROCKET_CLIENT_TYPE, )
async def inner_test() -> None: async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client(TestingService, host=ip, port=port) as client: options = RpcOptions() options.timeout = 100.0 self.assertEqual("Testing", await client.getName(rpc_options=options)) self.assertEqual("true", options.read_headers["contextvar"]) self.assertEqual( "getMethodName", await client.getMethodName(), ) # requestId is a 16 char wide hex string self.assertEqual( len(await client.getRequestId()), 16, ) self.assertEqual( 100.0, await client.getRequestTimeout(rpc_options=options), )
async def inner_test() -> None: async with TestServer() as sa: port = sa.port assert port async with get_client(TestingService, host=hostname, port=port) as client: self.assertTrue(await client.invert(False)) self.assertFalse(await client.invert(True))
async def inner_test() -> None: async with TestServer(handler=CppHandler()) as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client(TestingService, host=ip, port=port) as client: with self.assertRaises(HardError): await client.hard_error(True) with self.assertRaises(UnicodeDecodeError): await client.hard_error(False)
async def inner_test() -> None: async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client(TestingService, host=ip, port=port) as client: options = RpcOptions() options.set_header("from client", "with love") self.assertFalse(await client.invert(True, rpc_options=options)) self.assertIn("from server", options.read_headers)
async def inner_test() -> None: async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client(TestingService, host=ip, port=port) as client: options = RpcOptions() self.assertEqual( "Testing", await client.getName(rpc_options=options) ) self.assertEqual("true", options.read_headers["contextvar"])
async def inner_test() -> None: async with TestServer() as sa: ip, port = sa.ip, sa.port assert ip and port client = get_client(TestingService, host=ip, port=port) await client.__aenter__() self.assertTrue(await client.invert(False)) self.assertFalse(await client.invert(True)) fut = client.__aexit__(None, None, None) del client # If we do not abort here then good
async def inner_test() -> None: async with TestServer(handler=DerivedHandler()) as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client(DerivedTestingService, host=ip, port=port) as client: self.assertEqual(await client.getName(), "DerivedTesting") self.assertEqual( await client.derived_pick_a_color(Color.red), Color.red)
async def inner_test() -> None: async with TestServer(handler=CancelHandler(), ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client(TestingService, host=ip, port=port) as client: with self.assertRaises(ApplicationError) as ex: await client.getName() self.assertEqual( ex.exception.message, f"Application was cancelled on the server with message: {cancelledMessage}", )
async def inner_test() -> None: async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client( TestingService, host=ip, port=port, client_type=ClientType.THRIFT_FRAMED_COMPACT, ) as client: self.assertTrue(await client.invert(False)) self.assertFalse(await client.invert(True))
async def client_call(sa: SocketAddress) -> str: ip, port = sa.ip, sa.port assert ip and port async with get_client(DerivedTestingService, host=ip, port=port) as client: try: return await client.getName() except ApplicationError as err: if "Queue Timeout" in str(err): return "Queue Timeout" else: return ""
async def inner_test() -> None: async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client( TestingService, host=ip, port=port, client_type=ClientType.THRIFT_UNFRAMED_DEPRECATED, protocol=Protocol.BINARY, ) as client: self.assertTrue(await client.invert(False)) self.assertFalse(await client.invert(True))
async def inner_test() -> None: async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client( StreamTestService, host=ip, port=port, client_type=ClientType.THRIFT_ROCKET_CLIENT_TYPE, ) as client: stream = await client.stringstream() res = [n async for n in stream] self.assertEqual(res, ["hi", "hello"])
async def inner_test() -> None: async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client( StreamTestService, host=ip, port=port, client_type=ClientType.THRIFT_ROCKET_CLIENT_TYPE, ) as client: stream = await client.returnstream(10, 1024) res = [n async for n in stream] self.assertEqual(res, list(range(10, 1024)))
async def inner_test() -> None: async with TestServer(handler=StackHandler(), ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client(StackService, host=ip, port=port) as client: self.assertEqual( (3, 4, 5, 6), await client.add_to(lst=(1, 2, 3, 4), value=2) ) self.assertEqual(66, (await client.get_simple()).val) await client.take_simple(simple(val=10)) self.assertEqual(b"abc", bytes(await client.get_iobuf())) await client.take_iobuf(IOBuf(b"cba")) # currently unsupported by cpp backend: # self.assertEqual(b'xyz', (await client.get_iobuf_ptr())) await client.take_iobuf_ptr(IOBuf(b"zyx"))
async def inner_test() -> None: async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client( StreamTestService, host=ip, port=port, client_type=ClientType.THRIFT_ROCKET_CLIENT_TYPE, ) as client: with self.assertRaises(FuncEx): await client.streamthrows(True) stream = await client.streamthrows(False) with self.assertRaises(StreamEx): async for _ in stream: # noqa: F841 current flake8 version too old to support "async for _ in" pass
async def inner_test() -> None: async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client( TestingService, host=ip, port=port, path="/some/endpoint", client_type=ClientType.THRIFT_HTTP_CLIENT_TYPE, ) as client: try: self.assertTrue(await client.invert(False)) except TransportError as err: # The test server gets an invalid request because its a HTTP request self.assertEqual(err.type.value, 4) # END OF FILE
def get_openr_ctrl_cpp_client( host: str, options: Optional[bunch.Bunch] = None, client_type=ClientType.THRIFT_HEADER_CLIENT_TYPE, ) -> OpenrCtrlCppClient: """ Utility function to get py3 OpenrClient. We must eventually move all of our client use-case to py3 as python2 support is deprecated. https://fburl.com/ef0eq78f Major Usecase for: py3 supports streaming """ options = options if options else getDefaultOptions(host) ssl_context = None # Create ssl context if specified if options.ssl: # Translate ssl verification option ssl_verify_opt = SSLVerifyOption.NO_VERIFY if options.cert_reqs == ssl.CERT_OPTIONAL: ssl_verify_opt = SSLVerifyOption.VERIFY_REQ_CLIENT_CERT if options.cert_reqs == ssl.CERT_REQUIRED: ssl_verify_opt = SSLVerifyOption.VERIFY # Create ssl context ssl_context = SSLContext() ssl_context.set_verify_option(ssl_verify_opt) ssl_context.load_cert_chain(certfile=options.cert_file, keyfile=options.key_file) ssl_context.load_verify_locations(cafile=options.ca_file) # Create and return client return get_client( OpenrCtrlCppClient, host=host, port=options.openr_ctrl_port, timeout=(options.timeout / 1000), # NOTE: Timeout expected is in seconds client_type=client_type, ssl_context=ssl_context, ssl_timeout=(options.timeout / 1000), # NOTE: Timeout expected is in seconds )
async def inner_test() -> None: async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client( StreamTestService, host=ip, port=port, client_type=ClientType.THRIFT_ROCKET_CLIENT_TYPE, ) as client: # pyre-fixme[23]: response and server stream aren't unpackable according to pyre resp, stream = await client.returnresponseandstream( Included(from_=39, to=42)) self.assertEqual(resp, Included(from_=100, to=200)) expected_to = 39 async for n in stream: self.assertEqual(n, Included(from_=39, to=expected_to)) expected_to += 1 self.assertEqual(expected_to, 42)
async def inner_test() -> None: async with TestServer(handler=BinaryHandler(self), ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port async with get_client(BinaryService, host=ip, port=port) as client: # pyre-fixme[33]: Given annotation cannot be `Any`. val: Any val = await client.sendRecvBinaries( Binaries( no_special_type=b"c1", iobuf_val=IOBuf(b"c2"), iobuf_ptr=IOBuf(b"c3"), fbstring=b"c4", nonstandard_type=b"c5", )) self.assertEqual(val.no_special_type, b"s1") self.assertEqual(bytes(val.iobuf_val), b"s2") assert val.iobuf_ptr is not None self.assertEqual(bytes(val.iobuf_ptr), b"s3") self.assertEqual(val.fbstring, b"s4") self.assertEqual(val.nonstandard_type, b"s5") val = await client.sendRecvBinary(b"cv1") self.assertEqual(val, b"sv1") val = await client.sendRecvIOBuf(IOBuf(b"cv2")) self.assertEqual(bytes(val), b"sv2") val = await client.sendRecvIOBufPtr(IOBuf(b"cv3")) self.assertEqual(bytes(val), b"sv3") val = await client.sendRecvFbstring(b"cv4") self.assertEqual(val, b"sv4") val = await client.sendRecvBuffer(b"cv5") self.assertEqual(val, b"sv5") bu = BinaryUnion(iobuf_val=IOBuf(b"cv6")) val = await client.sendRecBinaryUnion(bu) self.assertEqual(bytes(val.iobuf_val), b"sv6")
async def inner_test() -> None: async with TestServer() as sa: ip, port = sa.ip, sa.port assert ip and port get_client(TestingService, host=ip, port=port)
async def bad_client_connect() -> None: async with get_client(TestingService, port=1) as client: await client.complex_action("foo", "bar", 9, "baz")
async def test() -> None: async with get_client(TestingService, port=1, headers={"foo": "bar"}): pass
async def connect_to_unlistened_socket() -> None: async with get_client(TestingService, path=socket_path): pass
async def inner_test(dir: Path) -> None: async with TestServer(path=dir / "tserver.sock") as sa: assert sa.path async with get_client(TestingService, path=sa.path) as client: self.assertTrue(await client.invert(False)) self.assertFalse(await client.invert(True))