def test_oneway_not_open(self): ctx = FContext("fooid") ctx.timeout = 10 frame = utils.mock_frame(ctx) transport = FAsyncTransportImpl(is_open=False) with self.assertRaises(TTransportException) as cm: yield transport.oneway(ctx, frame) self.assertEqual(TTransportExceptionType.NOT_OPEN, cm.exception.type) self.assertIsNone(transport._payload)
async def test_oneway_timeout(self): ctx = FContext("fooid") ctx.timeout = 10 frame = utils.mock_frame(ctx) transport = FAsyncTransportImpl(flush_wait=1) with self.assertRaises(TTransportException) as cm: await transport.oneway(ctx, frame) self.assertEqual(TTransportExceptionType.TIMED_OUT, cm.exception.type) self.assertEqual(frame, transport._payload)
def test_oneway_size_exception(self): ctx = FContext("fooid") ctx.timeout = 10 frame = utils.mock_frame(ctx) transport = FAsyncTransportImpl(request_size_limit=1) with self.assertRaises(TTransportException) as cm: yield transport.oneway(ctx, frame) self.assertEqual(TTransportExceptionType.REQUEST_TOO_LARGE, cm.exception.type) self.assertIsNone(transport._payload)
async def test_request_not_open(self): ctx = FContext("fooid") ctx.timeout = 10 frame = utils.mock_frame(ctx) transport = FAsyncTransportImpl(is_open=False) with self.assertRaises(TTransportException) as cm: await transport.request(ctx, frame) self.assertEqual(TTransportExceptionType.NOT_OPEN, cm.exception.type) self.assertEqual(0, len(transport._futures)) self.assertIsNone(transport._payload)
def test_request_response_timeout(self): ctx = FContext("fooid") ctx.timeout = 10 frame = utils.mock_frame(ctx) transport = FAsyncTransportImpl() with self.assertRaises(TTransportException) as cm: yield transport.request(ctx, frame) self.assertEqual(TTransportExceptionType.TIMED_OUT, cm.exception.type) self.assertEqual("request timed out", cm.exception.message) self.assertEqual(0, len(transport._futures)) self.assertEqual(frame, transport._payload)
def test_request_pending(self): ctx = FContext("fooid") ctx.timeout = 100 frame = utils.mock_frame(ctx) transport = FAsyncTransportImpl() with self.assertRaises(TTransportException) as cm: transport.request(ctx, frame), yield transport.request(ctx, frame) self.assertEqual(TTransportExceptionType.UNKNOWN, cm.exception.type) self.assertEqual("request already in flight for context", cm.exception.message) # We still have one request pending self.assertEqual(1, len(transport._futures))