Exemple #1
0
 def test_chunk_buffer_size(self) -> None:
     options = RpcOptions()
     self.assertEquals(options.chunk_buffer_size, 100)  # default value
     options.chunk_buffer_size = 200
     self.assertEquals(options.chunk_buffer_size, 200)
     with self.assertRaises(TypeError):
         options.chunk_buffer_size = "1"  # type: ignore
Exemple #2
0
        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),
                    )
Exemple #3
0
 def test_priority(self) -> None:
     options = RpcOptions()
     self.assertIsInstance(options.priority, Priority)
     options.priority = Priority.HIGH
     self.assertEquals(options.priority, Priority.HIGH)
     with self.assertRaises(TypeError):
         options.priority = 1  # type: ignore
 def test_chunk_buffer_size(self) -> None:
     options = RpcOptions()
     self.assertEquals(options.chunk_buffer_size, 100)  # default value
     options.chunk_buffer_size = 200
     self.assertEquals(options.chunk_buffer_size, 200)
     with self.assertRaises(TypeError):
         # pyre-fixme[8]: Attribute has type `int`; used as `str`.
         options.chunk_buffer_size = "1"
 def test_priority(self) -> None:
     options = RpcOptions()
     self.assertIsInstance(options.priority, Priority)
     options.priority = Priority.HIGH
     self.assertEquals(options.priority, Priority.HIGH)
     with self.assertRaises(TypeError):
         # pyre-fixme[8]: Attribute has type `Priority`; used as `int`.
         options.priority = 1
Exemple #6
0
 def test_timeout(self) -> None:
     options = RpcOptions()
     self.assertEqual(0, options.timeout)
     options.timeout = 0.05
     self.assertEqual(0.05, options.timeout)
     options.chunk_timeout = options.queue_timeout = options.timeout
     self.assertEqual(options.chunk_timeout, options.queue_timeout)
     with self.assertRaises(TypeError):
         options.timeout = "1"  # type: ignore
Exemple #7
0
 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)
 def test_timeout(self) -> None:
     options = RpcOptions()
     self.assertEqual(0, options.timeout)
     options.timeout = 0.05
     self.assertEqual(0.05, options.timeout)
     options.chunk_timeout = options.queue_timeout = options.timeout
     self.assertEqual(options.chunk_timeout, options.queue_timeout)
     with self.assertRaises(TypeError):
         # pyre-fixme[8]: Attribute has type `float`; used as `str`.
         options.timeout = "1"
 async def inner_test() -> None:
     options = RpcOptions()
     options.chunk_buffer_size = 64
     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,
                                                rpc_options=options)
             res = [n async for n in stream]
             self.assertEqual(res, list(range(10, 1024)))
Exemple #10
0
 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"])
Exemple #11
0
 def test_write_headers(self) -> None:
     options = RpcOptions()
     headers = options.write_headers
     self.assertIsInstance(headers, WriteHeaders)
     options.set_header("test", "test")
     self.assertTrue(options.write_headers is headers)
     self.assertIn("test", headers)
     self.assertEqual(headers["test"], "test")
     with self.assertRaises(TypeError):
         options.set_header("count", 1)  # type: ignore
 def test_write_headers(self) -> None:
     options = RpcOptions()
     headers = options.write_headers
     self.assertIsInstance(headers, WriteHeaders)
     options.set_header("test", "test")
     self.assertTrue(options.write_headers is headers)
     self.assertIn("test", headers)
     self.assertEqual(headers["test"], "test")
     with self.assertRaises(TypeError):
         # pyre-fixme[6]: Expected `str` for 2nd param but got `int`.
         options.set_header("count", 1)