From 70eef57fdd3149d22e87243568531ee08c58d2ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20S=C3=A1nchez=20Parra?= Date: Thu, 1 Dec 2022 17:35:05 +0100 Subject: [PATCH] Refactor deprecate_eof_cache-t to compare against inserted values Use the vector which contains inserted data to validate received data from ProxySQL. --- .../deprecate_eof_cache-t.cpp | 54 ++++++++++++++++--- .../deprecate_eof_support/fwd_eof_query.cpp | 10 ++-- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/test/tap/tests_with_deps/deprecate_eof_support/deprecate_eof_cache-t.cpp b/test/tap/tests_with_deps/deprecate_eof_support/deprecate_eof_cache-t.cpp index 3517b49b7..f13b80083 100644 --- a/test/tap/tests_with_deps/deprecate_eof_support/deprecate_eof_cache-t.cpp +++ b/test/tap/tests_with_deps/deprecate_eof_support/deprecate_eof_cache-t.cpp @@ -194,11 +194,30 @@ int main(int argc, char** argv) { return exit_status(); } + const nlohmann::json ok_query_res_json = nlohmann::json::parse(ok_query_res); + + const std::string ok_res_id = ok_query_res_json["Result"][0]["id"]; + ok( + ok_res_id == std::to_string(id), + "EOF to OK -> inserted id: %d // received id: %s", + id, + ok_res_id.c_str() + ); + + const std::string ok_res_c = ok_query_res_json["Result"][0]["c"]; + ok( + ok_res_c == stored_pairs[i].first, + "EOF to OK -> inserted c: %s // received c: %s", + stored_pairs[i].first.c_str(), + ok_res_c.c_str() + ); + + const std::string ok_res_pad = ok_query_res_json["Result"][0]["pad"]; ok( - eof_query_res == ok_query_res, - "EOF to OK: ['eof_query_res': %s] should match ['ok_query_res': %s]", - eof_query_res.c_str(), - ok_query_res.c_str() + ok_res_pad == stored_pairs[i].second, + "EOF to OK -> inserted pad: %s // received pad: %s", + stored_pairs[i].second.c_str(), + ok_res_pad.c_str() ); // Wait for invalidation of query_cache @@ -219,11 +238,30 @@ int main(int argc, char** argv) { return exit_status(); } + const nlohmann::json eof_query_res_json = nlohmann::json::parse(eof_query_res); + + const std::string eof_res_id = eof_query_res_json["Result"][0]["id"]; + ok( + eof_res_id == std::to_string(id), + "OK to EOF -> inserted id: %d // received id: %s", + id, + eof_res_id.c_str() + ); + + const std::string eof_res_c = eof_query_res_json["Result"][0]["c"]; + ok( + eof_res_c == stored_pairs[i].first, + "OK to EOF -> inserted c: %s // received c: %s", + stored_pairs[i].first.c_str(), + eof_res_c.c_str() + ); + + const std::string eof_res_pad = eof_query_res_json["Result"][0]["pad"]; ok( - eof_query_res == ok_query_res, - "OK to EOF: ['eof_query_res': %s] should match ['ok_query_res': %s]", - eof_query_res.c_str(), - ok_query_res.c_str() + eof_res_pad == stored_pairs[i].second, + "OK to EOF -> inserted pad: %s // received pad: %s", + stored_pairs[i].second.c_str(), + eof_res_pad.c_str() ); } diff --git a/test/tap/tests_with_deps/deprecate_eof_support/fwd_eof_query.cpp b/test/tap/tests_with_deps/deprecate_eof_support/fwd_eof_query.cpp index 8c232d6a6..230496d8a 100644 --- a/test/tap/tests_with_deps/deprecate_eof_support/fwd_eof_query.cpp +++ b/test/tap/tests_with_deps/deprecate_eof_support/fwd_eof_query.cpp @@ -114,14 +114,14 @@ int main(int argc, char** argv) { if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { std::string err_msg { "MySQL Error:" + std::string { mysql_error(proxy) }+ "" }; - std::cerr << "{ Code: Err, Result: " << err_msg << " }"; + std::cerr << "{ \"Code\": \"Err\", \"Result\": \"" << err_msg << "\" }"; return -1; } int query_res = mysql_query(proxy, query.c_str()); if (query_res != 0) { std::string err_msg { "MySQL Error:" + std::string { mysql_error(proxy) }+ "" }; - std::cerr << "{ Code: Err, Result: " << err_msg << " }"; + std::cerr << "{ \"Code\": \"Err\", \"Result\": \"" << err_msg << "\" }"; return -1; } @@ -131,19 +131,19 @@ int main(int argc, char** argv) { if (select_res != NULL) { json j_res {}; MySQL_result_to_JSON(select_res, j_res); - std::cout << "{ Code: OK, Result: " << j_res.dump() << " }"; + std::cout << "{ \"Code\": \"OK\", \"Result\": " << j_res.dump() << " }"; } else { std::string err_msg { "MySQL Error: " + std::string { mysql_error(proxy) }+ "" }; - std::cerr << "{ Code: Err, Result: " << err_msg << " }"; + std::cerr << "{ \"Code\": \"Err\", \"Result\": \"" << err_msg << "\" }"; res_code = -1; } mysql_free_result(select_res); } else { std::string err_msg { "MySQL Error:" + std::string { mysql_error(proxy) }+ "" }; - std::cerr << "{ Code: OK, Result: 0 }"; + std::cerr << "{ \"Code\": \"OK\", \"Result\": 0 }"; } mysql_close(proxy);