def test_handle_response_none(self): transport = FAsyncTransport() ctx = FContext() future = Future() transport._futures[str(ctx._get_op_id())] = future yield transport.handle_response(None) self.assertFalse(future.done())
def test_handle_response_unregistered_op_id(self): transport = FAsyncTransport() ctx1 = FContext() ctx2 = FContext() future = Future() transport._futures[str(ctx1._get_op_id())] = future yield transport.handle_response(utils.mock_frame(ctx2)) self.assertFalse(future.done())
async def request(self, context: FContext, payload): self._preflight_request_check(payload) op_id = str(context._get_op_id()) future = asyncio.Future() async with self._futures_lock: if op_id in self._futures: raise TTransportException( type=TTransportExceptionType.UNKNOWN, message="request already in flight for context") self._futures[op_id] = future try: with async_timeout.timeout(context.timeout / 1000): await self.flush(payload) return TMemoryBuffer(await future) except asyncio.TimeoutError: raise TTransportException(type=TTransportExceptionType.TIMED_OUT, message='request timed out') from None finally: async with self._futures_lock: del self._futures[op_id]