From cda3fef7463b2bf30b7498109e90a3ce0d9824ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Fri, 26 Mar 2021 10:05:33 +0100 Subject: [PATCH] Added regression test 'reg_test_3184-set_wait_timeout-t.cpp' for changes to 'SET wait_timeout' handling --- .../reg_test_3184-set_wait_timeout-t.cpp | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 test/tap/tests/reg_test_3184-set_wait_timeout-t.cpp diff --git a/test/tap/tests/reg_test_3184-set_wait_timeout-t.cpp b/test/tap/tests/reg_test_3184-set_wait_timeout-t.cpp new file mode 100644 index 000000000..399f85dd6 --- /dev/null +++ b/test/tap/tests/reg_test_3184-set_wait_timeout-t.cpp @@ -0,0 +1,93 @@ +/** + * @file reg_test_3184-set_wait_timeout-t.cpp + * @brief This test is a regression test for issue #3184. + * @details The test performs all the valid supported combinations of + * 'SET @@wait_timeout' queries that ProxySQL should ignore, returning + * an okay packet. The check is performed via 'PROXYSQL INTERNAL SESSION', + * checking that multiplexing hasn't been disable due to an unknown + * 'SET' statement. + * + * @date 2021-03-26 + */ + +#include +#include +#include +#include + +#include "tap.h" +#include "command_line.h" +#include "utils.h" +#include "json.hpp" + +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. + */ +std::vector valids_set_wait_timeout { + "SET @@wait_timeout = 2147483", + "SET @@wait_timeout=2147483", + "SET @@SESSION.wait_timeout = 2147483", + "SET @@SESSION.wait_timeout=2147483", + "SET wait_timeout = 2147483", + "SET wait_timeout=2147483", + "SET SESSION wait_timeout = 2147483", + "SET SESSION wait_timeout=2147483" +}; + +int main(int argc, char** argv) { + CommandLine cl; + + if (cl.getEnv()) { + diag("Failed to get the required environmental variables."); + return -1; + } + + plan(2 * valids_set_wait_timeout.size()); + + MYSQL* proxysql_mysql = mysql_init(NULL); + + if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); + return -1; + } + + for (const auto& set_wait_timeout : valids_set_wait_timeout) { + 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); + + bool found_backends = j_status.contains("backends"); + ok(found_backends == false, "No backends should be found for the current connection."); + } + + mysql_close(proxysql_mysql); + + return exit_status(); +}