Remove duplicate code from several tests

pull/4306/head
Javier Jaramago Fernández 3 years ago
parent f35cebfb3a
commit 3843a54bed

@ -23,24 +23,6 @@
using std::string;
using namespace nlohmann;
/**
* @brief Helper function to convert a 'MYSQL_RES' into a
* nlohmann::json.
*
* @param result The 'MYSQL_RES*' to be converted into JSON.
* @param j 'nlohmann::json' output parameter holding the
* converted 'MYSQL_RES' supplied.
*/
void parse_result_json_column(MYSQL_RES *result, json& j) {
if(!result) return;
MYSQL_ROW row;
while ((row = mysql_fetch_row(result))) {
j = json::parse(row[0]);
}
}
/**
* @brief Valid variations of 'SET wait_timeout' supported
* by ProxySQL to be ignored.
@ -96,12 +78,7 @@ int main(int argc, char** argv) {
int query_err = mysql_query(proxysql_mysql, set_wait_timeout.c_str());
ok (query_err == 0, "Query '%s' should be properly executed.", set_wait_timeout.c_str());
MYSQL_QUERY(proxysql_mysql, "PROXYSQL INTERNAL SESSION");
json j_status {};
MYSQL_RES* int_session_res = mysql_store_result(proxysql_mysql);
parse_result_json_column(int_session_res, j_status);
mysql_free_result(int_session_res);
json j_status = fetch_internal_session(proxysql_mysql);
bool found_backends = j_status.contains("backends");
ok(found_backends == false, "No backends should be found for the current connection.");
}

@ -45,15 +45,7 @@ void parse_result_json_column(MYSQL_RES *result, json& j) {
int get_session_schemaname(MYSQL* proxysql, std::string& schemaname) {
int res = EXIT_FAILURE;
json j_status;
int query_res = mysql_query(proxysql, "PROXYSQL INTERNAL SESSION");
if (query_res) {
return query_res;
}
MYSQL_RES* tr_res = mysql_store_result(proxysql);
parse_result_json_column(tr_res, j_status);
mysql_free_result(tr_res);
json j_status = fetch_internal_session(proxysql);
try {
schemaname = j_status["client"]["userinfo"]["schemaname"];

@ -82,20 +82,10 @@ int get_query_result(MYSQL* mysql, const string& query, uint64_t& out_val) {
#define log_err(err_msg) fprintf(stderr, "File %s, line %d, Error: \"%s\"\n", __FILE__, __LINE__, err_msg);
int get_conn_auto_inc_delay_token(MYSQL* proxy_mysql, int& out_auto_inc_delay) {
MYSQL_QUERY(proxy_mysql, "PROXYSQL INTERNAL SESSION");
MYSQL_RES* my_res = mysql_store_result(proxy_mysql);
vector<mysql_res_row> int_sess_res = extract_mysql_rows(my_res);
mysql_free_result(my_res);
int cur_auto_inc_delay_mult = 0;
if (int_sess_res.empty()) {
log_err("Empty result received from 'PROXYSQL INTERNAL SESSION'");
return EXIT_FAILURE;
}
try {
nlohmann::json j_int_sess = nlohmann::json::parse(int_sess_res[0][0]);
nlohmann::json j_int_sess = fetch_internal_session(proxy_mysql);
nlohmann::json backend_conns = j_int_sess.at("backends");
nlohmann::json m_off_conn {};
@ -124,20 +114,8 @@ int get_conn_auto_inc_delay_token(MYSQL* proxy_mysql, int& out_auto_inc_delay) {
}
int get_session_backends(MYSQL* proxy_mysql,vector<json>& out_backend_conns) {
MYSQL_QUERY(proxy_mysql, "PROXYSQL INTERNAL SESSION");
MYSQL_RES* my_res = mysql_store_result(proxy_mysql);
vector<mysql_res_row> int_sess_res = extract_mysql_rows(my_res);
mysql_free_result(my_res);
int cur_auto_inc_delay_mult = 0;
if (int_sess_res.empty()) {
log_err("Empty result received from 'PROXYSQL INTERNAL SESSION'");
return EXIT_FAILURE;
}
try {
nlohmann::json j_int_sess = nlohmann::json::parse(int_sess_res[0][0]);
nlohmann::json j_int_sess = fetch_internal_session(proxy_mysql);
nlohmann::json backend_conns = j_int_sess.at("backends");
vector<json> _out_conns {};

@ -33,23 +33,6 @@
using std::string;
using namespace nlohmann;
/**
* @brief Helper function to convert a 'MYSQL_RES' into a
* nlohmann::json.
*
* @param result The 'MYSQL_RES*' to be converted into JSON.
* @param j 'nlohmann::json' output parameter holding the
* converted 'MYSQL_RES' supplied.
*/
void parse_result_json_column(MYSQL_RES *result, json& j) {
if(!result) return;
MYSQL_ROW row;
while ((row = mysql_fetch_row(result))) {
j = json::parse(row[0]);
}
}
using user_attributes = std::tuple<std::string, std::string, std::string, std::string>;
/**
@ -87,11 +70,7 @@ int check_front_conn_isolation_level(
const std::string& exp_iso_level,
const bool set_via_attr
) {
MYSQL_QUERY(proxysql_mysql, "PROXYSQL INTERNAL SESSION");
json j_status {};
MYSQL_RES* int_session_res = mysql_store_result(proxysql_mysql);
parse_result_json_column(int_session_res, j_status);
mysql_free_result(int_session_res);
json j_status = fetch_internal_session(proxysql_mysql);
try {
std::string front_conn_isolation_level =
@ -145,6 +124,7 @@ int check_backend_conn_isolation_level(
// Verify that the query produced a correct result
if (trx_iso_row && trx_iso_row[0]) {
trx_iso_val = std::string { trx_iso_row[0] };
mysql_free_result(trx_iso_res);
} else {
const std::string err_msg {
"Empty result received from query '" + select_trx_iso_query + "'"
@ -335,5 +315,8 @@ int main(int argc, char** argv) {
mysql_close(proxysql_mysql);
}
mysql_close(proxysql_admin);
mysql_close(mysql_server);
return exit_status();
}

@ -18,15 +18,6 @@
using std::string;
using namespace nlohmann;
void parse_result_json_column(MYSQL_RES *result, json& j) {
if(!result) return;
MYSQL_ROW row;
while ((row = mysql_fetch_row(result))) {
j = json::parse(row[0]);
}
}
std::vector<std::string> select_queries {
"select @@session.autocommit, @@session.big_tables, @@autocommit,@@bulk_insert_buffer_size, @@character_set_database,@@transaction_isolation, @@version,@@session.transaction_isolation",
"select @@autocommit, @@sql_mode, @@big_tables, @@autocommit,@@bulk_insert_buffer_size, @@character_set_database,@@session.transaction_isolation, @@version,@@transaction_isolation",
@ -53,11 +44,7 @@ int check_multiplexing_disabled(const CommandLine& cl, const std::string query,
MYSQL_RES* dummy_res = mysql_store_result(proxysql_mysql);
mysql_free_result(dummy_res);
MYSQL_QUERY(proxysql_mysql, "PROXYSQL INTERNAL SESSION");
json j_status {};
MYSQL_RES* int_session_res = mysql_store_result(proxysql_mysql);
parse_result_json_column(int_session_res, j_status);
mysql_free_result(int_session_res);
json j_status = fetch_internal_session(proxysql_mysql);
if (j_status.contains("backends")) {
for (auto& backend : j_status["backends"]) {

Loading…
Cancel
Save