def test_close_on_error(self): port = find_unused_port() tr1, pr1 = self.loop.run_until_complete( aiozmq.create_zmq_connection( lambda: Protocol(self.loop), zmq.REQ, bind="tcp://127.0.0.1:{}".format(port), ) ) handler = mock.Mock() self.loop.set_exception_handler(handler) sock = tr1.get_extra_info("zmq_socket") sock.close() tr1.write([b"data"]) self.assertTrue(tr1._closing) handler.assert_called_with( self.loop, { "protocol": pr1, "exception": mock.ANY, "transport": tr1, "message": "Fatal write error on zmq socket transport", }, ) # expecting 'Socket operation on non-socket' if sys.platform == "darwin": errno = 38 else: errno = 88 check_errno(errno, handler.call_args[0][1]["exception"])
def test_close_on_error(self): port = find_unused_port() tr1, pr1 = self.loop.run_until_complete( aiozmq.create_zmq_connection( lambda: Protocol(self.loop), zmq.REQ, bind='tcp://127.0.0.1:{}'.format(port), loop=self.loop)) handler = mock.Mock() self.loop.set_exception_handler(handler) sock = tr1.get_extra_info('zmq_socket') sock.close() tr1.write([b'data']) self.assertTrue(tr1._closing) handler.assert_called_with( self.loop, { 'protocol': pr1, 'exception': mock.ANY, 'transport': tr1, 'message': 'Fatal write error on zmq socket transport' }) # expecting 'Socket operation on non-socket' if sys.platform == 'darwin': errno = 38 else: errno = 88 check_errno(errno, handler.call_args[0][1]['exception'])
def test_close_on_error(self): port = find_unused_port() tr1, pr1 = self.loop.run_until_complete(aiozmq.create_zmq_connection( lambda: Protocol(self.loop), zmq.REQ, bind='tcp://127.0.0.1:{}'.format(port), loop=self.loop)) handler = mock.Mock() self.loop.set_exception_handler(handler) sock = tr1.get_extra_info('zmq_socket') sock.close() tr1.write([b'data']) self.assertTrue(tr1._closing) handler.assert_called_with( self.loop, {'protocol': pr1, 'exception': mock.ANY, 'transport': tr1, 'message': 'Fatal write error on zmq socket transport'}) # expecting 'Socket operation on non-socket' if sys.platform == 'darwin': errno = 38 else: errno = 88 check_errno(errno, handler.call_args[0][1]['exception'])
def test_write_common_error(self): self.sock.send_multipart.side_effect = zmq.ZMQError(errno.ENOTSUP) self.tr.write((b'a', b'b')) self.sock.send_multipart.assert_called_once_with((b'a', b'b'), zmq.DONTWAIT) self.assertFalse(self.proto.pause_writing.called) self.assertFalse(self.tr._buffer) self.assertEqual(0, self.tr._buffer_size) self.assertNotIn(self.sock, self.loop.writers) check_errno(errno.ENOTSUP, self.exc_handler.call_args[0][1]['exception'])
def test_write_common_error(self): self.sock.send_multipart.side_effect = zmq.ZMQError(errno.ENOTSUP) self.tr.write((b'a', b'b')) self.sock.send_multipart.assert_called_once_with( (b'a', b'b'), zmq.DONTWAIT) self.assertFalse(self.proto.pause_writing.called) self.assertFalse(self.tr._buffer) self.assertEqual(0, self.tr._buffer_size) self.assertNotIn(self.sock, self.loop.writers) check_errno(errno.ENOTSUP, self.exc_handler.call_args[0][1]['exception'])
async def go(): s1 = await aiozmq.create_zmq_stream( zmq.REP, bind="tcp://127.0.0.1:{}".format(port)) handler = mock.Mock() self.loop.set_exception_handler(handler) s1.write([b"data"]) with self.assertRaises(OSError) as ctx: await s1.read() check_errno(zmq.EFSM, ctx.exception) with self.assertRaises(OSError) as ctx2: await s1.drain() check_errno(zmq.EFSM, ctx2.exception)
def go(): s1 = yield from aiozmq.create_zmq_stream( zmq.REP, bind='tcp://127.0.0.1:{}'.format(port), loop=self.loop) handler = mock.Mock() self.loop.set_exception_handler(handler) s1.write([b'data']) with self.assertRaises(OSError) as ctx: yield from s1.read() check_errno(zmq.EFSM, ctx.exception) with self.assertRaises(OSError) as ctx2: yield from s1.drain() check_errno(zmq.EFSM, ctx2.exception)