Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Client/Connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class Connection
template <class T>
rid_t call(const std::string &func, const T &args);
rid_t ping();

/**
* Execute the SQL statement contained in the 'statement' parameter.
* @param statement statement, which should conform to the rules for SQL grammar
Expand Down
2 changes: 1 addition & 1 deletion src/Client/RequestEncoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ RequestEncoder<BUFFER>::encodeCall(const std::string &func, const T &args)
encodeHeader(Iproto::CALL);
mpp::encode(m_Buf, mpp::as_map(std::forward_as_tuple(
MPP_AS_CONST(Iproto::FUNCTION_NAME), func,
MPP_AS_CONST(Iproto::TUPLE), mpp::as_arr(args))));
MPP_AS_CONST(Iproto::TUPLE), args)));
uint32_t request_size = (m_Buf.end() - request_start) - PREHEADER_SIZE;
++request_start;
request_start.set(__builtin_bswap32(request_size));
Expand Down
4 changes: 2 additions & 2 deletions src/Client/ResponseReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ template<class BUFFER>
struct Data {
using it_t = iterator_t<BUFFER>;
std::pair<it_t, it_t> iters;

/** Unpacks tuples to passed container. */
template<class T>
bool decode(T& tuples)
{
it_t itr = iters.first;
bool ok = mpp::decode(itr, tuples);
assert(itr == iters.second);
assert(!ok || itr == iters.second);
return ok;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Base64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ std::pair<INP, OUT> decode(INP first, INP last, OUT dest)
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377";

while (true) {
if (BASE64_UNLIKELY(first == last))
return {first, dest};
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Mempool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class MempoolInstance : public MempoolStats<ENABLE_STATS> {
static_assert(sizeof(Slab) == B * M, "Smth went wrong");
static constexpr size_t FIRST_OFFSET = B - sizeof(Slab::next);

using Stats_t = MempoolStats<ENABLE_STATS>;
using Stats_t = MempoolStats<ENABLE_STATS>;

public:
// Constants for stat.
Expand Down Expand Up @@ -253,7 +253,7 @@ class MempoolStatic {
public:
static char *allocate() { return instance().allocate(); }
static void deallocate(char *ptr) noexcept { instance().deallocate(ptr); }
int selfcheck() const { return instance().selfcheck(); }
int selfcheck() const { return instance().selfcheck(); }

static constexpr size_t REAL_SIZE = Base_t::REAL_SIZE;
static constexpr size_t BLOCK_SIZE = Base_t::BLOCK_SIZE;
Expand Down
2 changes: 1 addition & 1 deletion src/mpp/Dec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ constexpr bool is_any_putable_v =
/**
* If it is true, the object of type T will not be decoded - raw data will
* be saved to it.
*
*
* Now it supports only a pair of iterators (probably, wrapped with
* mpp::as_raw). The check implicilty implies that BUF is an iterator, not
* buffer - it would be strange to pass a pair of buffer to decoder.
Expand Down
2 changes: 1 addition & 1 deletion test/ClientPerfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ executeRequest(Connection<BUFFER, NetProvider> &conn, int request_type, int key)
case Iproto::SELECT:
return conn.space[space_id].select(std::make_tuple(key));
case Iproto::CALL:
return conn.call("bench_func", std::make_tuple(1, 2, 3, 4, 5));
return conn.call("remote_echo", std::make_tuple(1, 2, 3, 4, 5));
default:
abort();
}
Expand Down
65 changes: 56 additions & 9 deletions test/ClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ printDatum(const Datum &datum)
*/
template <class BUFFER, class Data = std::vector<UserTuple>>
void
printResponse(Response<BUFFER> &response, Data data = std::vector<UserTuple>())
printResponse(Response<BUFFER> &response, Data data = std::vector<UserTuple>())
{
if (response.body.error_stack != std::nullopt) {
Error err = (*response.body.error_stack)[0];
Expand Down Expand Up @@ -588,6 +588,7 @@ single_conn_call(Connector<BUFFER, NetProvider> &client)
const static char *return_multi = "remote_multi";
const static char *return_nil = "remote_nil";
const static char *return_map = "remote_map";
const static char *echo = "remote_echo";

Connection<Buf_t, NetProvider> conn(client);
int rc = test_connect(client, conn, localhost, port);
Expand Down Expand Up @@ -671,6 +672,15 @@ single_conn_call(Connector<BUFFER, NetProvider> &client)
printResponse<BUFFER>(*response,
std::make_tuple(std::make_tuple(std::make_pair("key", int()))));

TEST_CASE("call remote_echo with raw arguments");
/* [1, 2, 3] as a raw MsgPack. */
const char raw_data[4] = {static_cast<char>(0x93), 1, 2, 3};
rid_t f11 = conn.call(echo, mpp::as_raw(raw_data));
client.wait(conn, f11, WAIT_TIMEOUT);
fail_unless(conn.futureIsReady(f11));
response = conn.getResponse(f11);
printResponse<BUFFER>(*response, std::make_tuple(std::make_tuple(0, 0, 0)));

client.close(conn);
}

Expand Down Expand Up @@ -699,7 +709,7 @@ class StmtProcessorPrepare {
std::string &stmt)
{
rid_t future = conn.prepare(stmt);

client.wait(conn, future, WAIT_TIMEOUT);
fail_unless(conn.futureIsReady(future));
std::optional<Response<Buf_t>> response = conn.getResponse(future);
Expand Down Expand Up @@ -769,7 +779,7 @@ single_conn_sql(Connector<BUFFER, NetProvider> &client)
"COLUMN2 VARCHAR(50), COLUMN3 DOUBLE);";
auto stmt = StmtProcessor::process(client, conn, stmt_str);
rid_t create_table = conn.execute(stmt, std::make_tuple());

client.wait(conn, create_table, WAIT_TIMEOUT);
fail_unless(conn.futureIsReady(create_table));
std::optional<Response<Buf_t>> response = conn.getResponse(create_table);
Expand All @@ -784,7 +794,7 @@ single_conn_sql(Connector<BUFFER, NetProvider> &client)
stmt_str = "INSERT INTO TSQL VALUES (20, 'first', 3.2), (21, 'second', 5.4)";
stmt = StmtProcessor::process(client, conn, stmt_str);
rid_t insert = conn.execute(stmt, std::make_tuple());

client.wait(conn, insert, WAIT_TIMEOUT);
fail_unless(conn.futureIsReady(insert));
response = conn.getResponse(insert);
Expand All @@ -803,7 +813,7 @@ single_conn_sql(Connector<BUFFER, NetProvider> &client)
stmt_str = "INSERT INTO TSQL VALUES (?, ?, ?), (?, ?, ?), (?, ?, ?);";
stmt = StmtProcessor::process(client, conn, stmt_str);
rid_t insert_args = conn.execute(stmt, args);

client.wait(conn, insert_args, WAIT_TIMEOUT);
fail_unless(conn.futureIsReady(insert_args));
response = conn.getResponse(insert_args);
Expand All @@ -818,7 +828,7 @@ single_conn_sql(Connector<BUFFER, NetProvider> &client)
stmt_str = "SELECT * FROM SEQSCAN TSQL;";
stmt = StmtProcessor::process(client, conn, stmt_str);
rid_t select = conn.execute(stmt, std::make_tuple());

client.wait(conn, select, WAIT_TIMEOUT);
fail_unless(conn.futureIsReady(select));
response = conn.getResponse(select);
Expand All @@ -841,7 +851,7 @@ single_conn_sql(Connector<BUFFER, NetProvider> &client)
stmt_str = "DROP TABLE IF EXISTS TSQL;";
stmt = StmtProcessor::process(client, conn, stmt_str);
rid_t drop_table = conn.execute(stmt, std::make_tuple());

client.wait(conn, drop_table, WAIT_TIMEOUT);
fail_unless(conn.futureIsReady(drop_table));
response = conn.getResponse(drop_table);
Expand Down Expand Up @@ -902,7 +912,7 @@ single_conn_sql(Connector<BUFFER, NetProvider> &client)
stmt_str = "SELECT * FROM SEQSCAN TSQL;";
stmt = StmtProcessor::process(client, conn, stmt_str);
select = conn.execute(stmt, std::make_tuple());

client.wait(conn, select, WAIT_TIMEOUT);
fail_unless(conn.futureIsReady(select));
response = conn.getResponse(select);
Expand Down Expand Up @@ -955,7 +965,7 @@ single_conn_sql(Connector<BUFFER, NetProvider> &client)
stmt_str = "UPDATE \"_session_settings\" SET \"value\" = false WHERE \"name\" = 'sql_full_metadata';";
stmt = StmtProcessor::process(client, conn, stmt_str);
rid_t disable_metadata = conn.execute(stmt, std::make_tuple());

client.wait(conn, disable_metadata, WAIT_TIMEOUT);
fail_unless(conn.futureIsReady(disable_metadata));
response = conn.getResponse(disable_metadata);
Expand Down Expand Up @@ -1083,6 +1093,42 @@ test_dead_connection_wait(Connector<BUFFER, NetProvider> &client)
#endif
}

/**
* Test for miscellaneous issues related to response decoding.
*/
template <class BUFFER, class NetProvider>
void
response_decoding(Connector<BUFFER, NetProvider> &client)
{
TEST_INIT(0);

Connection<Buf_t, NetProvider> conn(client);
int rc = test_connect(client, conn, localhost, port);
fail_unless(rc == 0);

TEST_CASE("decode data with non-matching format");
rid_t f = conn.call("remote_uint", std::make_tuple());
client.wait(conn, f, WAIT_TIMEOUT);
fail_unless(conn.futureIsReady(f));
std::optional<Response<Buf_t>> response = conn.getResponse(f);

fail_unless(response.has_value());
fail_unless(response->body.data.has_value());

std::string str;
unsigned num;
std::tuple<std::string> arr_of_str;
std::tuple<unsigned> arr_of_num;
/* Try to decode data with non-matching format. */
fail_if(response->body.data->decode(str));
fail_if(response->body.data->decode(num));
fail_if(response->body.data->decode(arr_of_str));
/* We should successfully decode data after all. */
fail_unless(response->body.data->decode(arr_of_num));

client.close(conn);
}

int main()
{
#ifdef TNTCXX_ENABLE_SSL
Expand Down Expand Up @@ -1131,5 +1177,6 @@ int main()
::test_sigpipe(client);
#endif
::test_dead_connection_wait(client);
response_decoding(client);
return 0;
}
14 changes: 7 additions & 7 deletions test/EncDecTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ test_raw()

using it_t = Buf_t::iterator_common<true>;
it_t run = buf.begin<true>();

std::pair<it_t, it_t> to_wrap;
auto raw_decoders = std::make_tuple(
std::pair<it_t, it_t>(),
Expand All @@ -1148,7 +1148,7 @@ test_raw()
fail_if(dec2.first != begin);
fail_if(dec2.second != end);
};

auto check_raw_decoders = [&](auto& begin, auto& end) {
std::apply([&](auto&... decs){(
...,
Expand Down Expand Up @@ -1185,7 +1185,7 @@ test_raw()
const auto arr_end = run;
TEST_CASE("decode the first element of array");
run = svp;
begin = run;
begin = run;
mpp::decode(run, mpp::as_arr(std::forward_as_tuple(num)));
fail_if(num != arr[0]);
fail_if(run != arr_end);
Expand All @@ -1203,7 +1203,7 @@ test_raw()
auto elem_begin = begin + 1;
auto elem_end = elem_begin;
mpp::decode(elem_end, num);
check_each_raw_decoder(elem_begin, elem_end);
check_each_raw_decoder(elem_begin, elem_end);
TEST_CASE("decode the array key by key");
run = svp;
// Array is small - its header occupies one byte.
Expand All @@ -1227,7 +1227,7 @@ test_raw()
const auto map_end = run;
TEST_CASE("decode one value from map");
run = svp;
begin = run;
begin = run;
mpp::decode(run, mpp::as_map(std::forward_as_tuple(1, num)));
fail_if(run != map_end);
fail_if(num != 2);
Expand All @@ -1248,7 +1248,7 @@ test_raw()
elem_end = elem_begin;
// Skip value.
mpp::decode(elem_end, num);
check_each_raw_decoder(elem_begin, elem_end);
check_each_raw_decoder(elem_begin, elem_end);
TEST_CASE("decode the map key by key");
run = svp;
// Map is small - its header occupies one byte.
Expand Down Expand Up @@ -1292,7 +1292,7 @@ test_variant()
mpp::encode(buf, wr);
mpp::decode(run, rd);
fail_unless(wr == rd);

wr.emplace<2>("string variant");
mpp::encode(buf, wr);
mpp::decode(run, rd);
Expand Down
2 changes: 1 addition & 1 deletion test/cfg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function remote_map()
return {key = 777}
end

function bench_func(...)
function remote_echo(...)
return {...}
end

Expand Down
2 changes: 1 addition & 1 deletion test/cfg_ssl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function remote_multi()
return 'Hello', 1, 6.66
end

function bench_func(...)
function remote_echo(...)
return {...}
end

Expand Down
Loading