def test_exception_status_code_is_set(server, ThriftTest, server_ttypes): # Given this test server: @server.thrift.register(ThriftTest) def testException(request): raise server_ttypes.Xception( errorCode=1001, message=request.body.arg ) # Make a call: conn = yield TornadoConnection.outgoing(server.hostport) res = yield conn.send( CallRequestMessage( service=b'service', headers={b'cn': b'client', b'as': b'thrift'}, args=[ b'ThriftTest::testException', b'', bytearray([ 0x0B, # type = string 0x00, 0x01, # field ID 1 0x00, 0x00, 0x00, 0x00, # empty string 0x00, # STOP ]), ], ) ) assert 1 == res.status_code
def test_get_rank_with_imcoming(): server = TChannel('server') server.listen() connection = yield TornadoConnection.outgoing(server.hostport) connection.direction = INCOMING peer = Peer(TChannel('test'), '10.10.101.21:230') calculator = PreferIncomingCalculator() peer.register_incoming_conn(connection) assert sys.maxint != calculator.get_rank(peer)
def test_get_rank_with_outgoing(): server = TChannel('server') server.listen() connection = yield TornadoConnection.outgoing(server.hostport) peer = Peer(TChannel('test'), '10.10.101.21:230') calculator = PreferIncomingCalculator() peer.register_outgoing_conn(connection) assert PreferIncomingCalculator.TIERS[1] == calculator.get_rank(peer)
def test_init_req_header(): with mock.patch.object( TornadoConnection, '_extract_handshake_headers', side_effect=verify_init_header, ) as mock_extract: mock_extract.return_value = None server = TChannel('test_server') server.listen() yield TornadoConnection.outgoing(server.hostport)
def test_outbound_pending_change(): server = TChannel('server') server.listen() connection = yield TornadoConnection.outgoing(server.hostport) c = [0] def outbound_pending_change_callback(): c[0] += 1 connection.set_outbound_pending_change_callback( outbound_pending_change_callback) connection.add_pending_outbound() assert c[0] == 1 connection.add_pending_outbound() assert c[0] == 2 connection.remove_pending_outbound() assert c[0] == 3 connection.remove_pending_outbound() assert c[0] == 4
def test_outbound_pending_change_propagate(peer): server = TChannel('server') server.listen() connection = yield TornadoConnection.outgoing(server.hostport) peer.register_incoming_conn(connection) b = [0] def conn_change_db(peer): b[0] += 1 peer.set_on_conn_change_callback(conn_change_db) connection.add_pending_outbound() assert b[0] == 1 connection.add_pending_outbound() assert b[0] == 2 connection.remove_pending_outbound() assert b[0] == 3 connection.remove_pending_outbound() assert b[0] == 4
def test_outbound_pending_change(): server = TChannel('server') server.listen() connection = yield TornadoConnection.outgoing(server.hostport) c = [0] def outbound_pending_change_callback(): c[0] += 1 connection.set_outbound_pending_change_callback( outbound_pending_change_callback ) connection.add_pending_outbound() assert c[0] == 1 connection.add_pending_outbound() assert c[0] == 2 connection.remove_pending_outbound() assert c[0] == 3 connection.remove_pending_outbound() assert c[0] == 4