From c237243a2f0b3c19a7df6cfce2edc5930263d7d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Thu, 14 May 2020 20:41:51 +0200 Subject: [PATCH 1/9] Fixes #2793: Update capabilities and max_allowed properly in case of 'switching_auth' --- lib/MySQL_Protocol.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index aa6e51fba3..849d096243 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -1551,6 +1551,7 @@ bool MySQL_Protocol::process_pkt_handshake_response(unsigned char *pkt, unsigned //(*myds)->switching_auth_stage=2; charset=(*myds)->tmp_charset; proxy_debug(PROXY_DEBUG_MYSQL_PROTOCOL,2,"Session=%p , DS=%p . Encrypted: %d , switching_auth: %d, auth_plugin_id: %d\n", (*myds)->sess, (*myds), (*myds)->encrypted, (*myds)->switching_auth_stage, auth_plugin_id); + capabilities = (*myds)->myconn->options.client_flag; goto __do_auth; } @@ -1558,6 +1559,7 @@ bool MySQL_Protocol::process_pkt_handshake_response(unsigned char *pkt, unsigned (*myds)->myconn->options.client_flag = capabilities; pkt += sizeof(uint32_t); max_pkt = CPY4(pkt); + (*myds)->myconn->options.max_allowed_pkt = max_pkt; pkt += sizeof(uint32_t); charset = *(uint8_t *)pkt; if ( (*myds)->encrypted == false ) { // client wants to use SSL @@ -2002,7 +2004,6 @@ bool MySQL_Protocol::process_pkt_handshake_response(unsigned char *pkt, unsigned if (ret==true) { - (*myds)->myconn->options.max_allowed_pkt=max_pkt; (*myds)->DSS=STATE_CLIENT_HANDSHAKE; if (!userinfo->username) // if set already, ignore From 9261e3187cc36535b01133b51317cacdb78743d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Thu, 14 May 2020 20:45:01 +0200 Subject: [PATCH 2/9] Fixes #1493: Update 'pkt_sid' in case of compressed connection --- lib/mysql_data_stream.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mysql_data_stream.cpp b/lib/mysql_data_stream.cpp index 8a7e70de08..8f7bfea397 100644 --- a/lib/mysql_data_stream.cpp +++ b/lib/mysql_data_stream.cpp @@ -880,6 +880,7 @@ int MySQL_Data_Stream::buffer2array() { proxy_debug(PROXY_DEBUG_PKT_ARRAY, 5, "Session=%p . Reading the header of a new compressed packet\n", sess); memcpy(&queueIN.hdr,queue_r_ptr(queueIN), sizeof(mysql_hdr)); queue_r(queueIN,sizeof(mysql_hdr)); + pkt_sid=queueIN.hdr.pkt_id; queueIN.pkt.size=queueIN.hdr.pkt_length+sizeof(mysql_hdr)+3; queueIN.pkt.ptr=l_alloc(queueIN.pkt.size); memcpy(queueIN.pkt.ptr, &queueIN.hdr, sizeof(mysql_hdr)); // immediately copy the header into the packet From cf5336d3d0250a6e66e1d84f8ce9a91afbc766fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Thu, 14 May 2020 21:07:56 +0200 Subject: [PATCH 3/9] Added helper function for simplifying executing a external command --- test/tap/tap/utils.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++ test/tap/tap/utils.h | 11 +++++ 2 files changed, 106 insertions(+) diff --git a/test/tap/tap/utils.cpp b/test/tap/tap/utils.cpp index e31c47e5f7..ea029e735e 100644 --- a/test/tap/tap/utils.cpp +++ b/test/tap/tap/utils.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "tap.h" #include "utils.h" @@ -102,3 +104,96 @@ int get_server_version(MYSQL *mysql, std::string& version) { return 0; } + +// Pipes definition +constexpr uint8_t NUM_PIPES = 3; +constexpr uint8_t PARENT_WRITE_PIPE = 0; +constexpr uint8_t PARENT_READ_PIPE = 1; +constexpr uint8_t PARENT_ERR_PIPE = 2; +int pipes[NUM_PIPES][2]; +// Pipe selection +constexpr uint8_t READ_FD = 0; +constexpr uint8_t WRITE_FD = 1; +// Parent pipes +const auto& PARENT_READ_FD = pipes[PARENT_READ_PIPE][READ_FD]; +const auto& PARENT_READ_ERR = pipes[PARENT_ERR_PIPE][READ_FD]; +const auto& PARENT_WRITE_FD = pipes[PARENT_WRITE_PIPE][WRITE_FD]; +// Child pipes +const auto& CHILD_READ_FD = pipes[PARENT_WRITE_PIPE][READ_FD]; +const auto& CHILD_WRITE_FD = pipes[PARENT_READ_PIPE][WRITE_FD]; +const auto& CHILD_WRITE_ERR = pipes[PARENT_ERR_PIPE][WRITE_FD]; + +int execvp(const std::string& cmd, const std::vector& argv, std::string& result) { + int err = 0; + std::string result_ = ""; + std::vector _argv = argv; + + // Append null to end of _argv for extra safety + _argv.push_back(nullptr); + + int outfd[2]; + int infd[2]; + + // Pipes for parent to write and read + pipe(pipes[PARENT_READ_PIPE]); + pipe(pipes[PARENT_WRITE_PIPE]); + pipe(pipes[PARENT_ERR_PIPE]); + + pid_t child_pid = fork(); + if(child_pid == 0) { + // Copy the pipe descriptors + dup2(CHILD_READ_FD, STDIN_FILENO); + dup2(CHILD_WRITE_FD, STDOUT_FILENO); + dup2(CHILD_WRITE_ERR, STDERR_FILENO); + + // Close no longer needed pipes + close(CHILD_READ_FD); + close(CHILD_WRITE_FD); + close(CHILD_WRITE_ERR); + + close(PARENT_READ_FD); + close(PARENT_READ_ERR); + close(PARENT_WRITE_FD); + + char** args = const_cast(_argv.data()); + err = execvp(cmd.c_str(), args); + + if (err) { + exit(errno); + } else { + exit(0); + } + } else { + char buffer[128]; + int count; + + // Close no longer needed pipes + close(CHILD_READ_FD); + close(CHILD_WRITE_FD); + close(CHILD_WRITE_ERR); + + waitpid(child_pid, &err, 0); + + if (err == 0) { + // Read from child’s stdout + count = read(PARENT_READ_FD, buffer, sizeof(buffer) - 1); + while (count > 0) { + buffer[count] = 0; + result_ += buffer; + count = 0; + } + } else { + // Read from child’s stderr + count = read(PARENT_READ_ERR, buffer, sizeof(buffer) - 1); + while (count > 0) { + buffer[count] = 0; + result_ += buffer; + count = 0; + } + } + } + + result = result_; + + return err; +} diff --git a/test/tap/tap/utils.h b/test/tap/tap/utils.h index ac740ec45f..b79effb9df 100644 --- a/test/tap/tap/utils.h +++ b/test/tap/tap/utils.h @@ -3,6 +3,7 @@ #include #include +#include #define MYSQL_QUERY(mysql, query) \ do { \ @@ -27,5 +28,15 @@ int select_config_file(MYSQL* mysql, std::string& resultset); } #endif +/** + * @brief Execute the given comand, and stores it's output. + * + * @param file File to be executed. + * @param argv Arguments to be given to the executable. + * @param result The output of the file execution. If the execution succeed it contains `stdout` output, + * in case of failure `stderr` contents are returned. + * @return int Zero in case of success, or the errno returned by `execvp` in case of failure. + */ +int execvp(const std::string& file, const std::vector& argv, std::string& result); #endif // #define UTILS_H From a85e7fc80c87c83b1dab111fb8b1ea131d125c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Thu, 14 May 2020 21:17:38 +0200 Subject: [PATCH 4/9] Added two new regression tests for fixes for #2793 and #1493 --- test/tap/tests/Makefile | 6 ++ .../reg_test_1493-mixed_compression-t.cpp | 94 +++++++++++++++++++ .../tap/tests/reg_test_2793-compression-t.cpp | 59 ++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 test/tap/tests/reg_test_1493-mixed_compression-t.cpp create mode 100644 test/tap/tests/reg_test_2793-compression-t.cpp diff --git a/test/tap/tests/Makefile b/test/tap/tests/Makefile index 1cab6ed7e2..99a98bed1d 100644 --- a/test/tap/tests/Makefile +++ b/test/tap/tests/Makefile @@ -103,3 +103,9 @@ aurora: aurora.cpp $(TAP_LIBDIR)/libtap.a test_tokenizer-t: test_tokenizer-t.cpp $(TAP_LIBDIR)/libtap.a g++ test_tokenizer-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(MYLIBS) -lproxysql -ltap -Wl,--no-as-needed -ldl -lpthread -o test_tokenizer-t -DGITVERSION=\"$(GIT_VERSION)\" + +1493_mixed_compression: reg_test_1493-mixed_compression-t.cpp + g++ -DTEST_AURORA -DDEBUG test_mixed_compression-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(OBJ) $(MYLIBS) -ltap -ldl $(STATIC_LIBS) -o reg_test_1493-mixed_compression-t -DGITVERSION=\"$(GIT_VERSION)\" + +2793_compression: reg_test_2793-compression-t.cpp + g++ -DTEST_AURORA -DDEBUG reg_test_2793-compression-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(OBJ) $(MYLIBS) -ltap -ldl $(STATIC_LIBS) -o reg_test_2793-compression-t -DGITVERSION=\"$(GIT_VERSION)\" diff --git a/test/tap/tests/reg_test_1493-mixed_compression-t.cpp b/test/tap/tests/reg_test_1493-mixed_compression-t.cpp new file mode 100644 index 0000000000..d420c0f309 --- /dev/null +++ b/test/tap/tests/reg_test_1493-mixed_compression-t.cpp @@ -0,0 +1,94 @@ +/** + * @file test_mixed_compression-t.cpp + * @brief This test is a regression test for issue #1493. + * @version v2.1.12 + * @date 2020-05-14 + */ + +#include +#include +#include + +#include +#include + +#include "tap.h" +#include "command_line.h" +#include "utils.h" + +using std::string; + +int main(int argc, char** argv) { + CommandLine cl; + + if (cl.getEnv()) { + diag("Failed to get the required environmental variables."); + return -1; + } + + plan(1); + + MYSQL* proxysql_admin = mysql_init(NULL); + MYSQL* proxysql_mysql = mysql_init(NULL); + + // Initialize connections + if (!proxysql_admin || !proxysql_mysql) { + if (!proxysql_admin) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); + } else { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); + } + return -1; + } + + // Connnect to local proxysql + if (!mysql_real_connect(proxysql_admin, "127.0.0.1", "admin", "admin", NULL, 6032, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); + return -1; + } + + const char* disable_select_query_rules = + "UPDATE mysql_query_rules SET active=0 WHERE match_digest='^SELECT'"; + const char* enable_select_query_rules = + "UPDATE mysql_query_rules SET active=1 WHERE match_digest='^SELECT'"; + const char* update_mysql_query_rules = + "INSERT INTO mysql_query_rules (active, username, match_digest, destination_hostgroup, apply, cache_ttl, comment) " + "VALUES (1,'root','^SELECT.*', 1, 1, 1000000, 'test_mixed_compression_rule')"; + const char* delete_mysql_query_rule = + "DELETE FROM mysql_query_rules WHERE " + "comment='test_mixed_compression_rule'"; + const char* load_mysql_queries_runtime = + "LOAD MYSQL QUERY RULES TO RUNTIME"; + + // Setup config - query_rules + MYSQL_QUERY(proxysql_admin, disable_select_query_rules); + MYSQL_QUERY(proxysql_admin, update_mysql_query_rules); + MYSQL_QUERY(proxysql_admin, load_mysql_queries_runtime); + + // Connect to mysql + if (!mysql_real_connect(proxysql_mysql, "127.0.0.1", "root", "root", NULL, 6033, NULL, CLIENT_COMPRESS)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); + return -1; + } + + // Mixed compressed / uncompressed queries test #1493 + const char* mysql_select_command = "mysql"; + std::vector n_auth_cargs = { "mysql", "-uroot", "-proot", "-h", "127.0.0.1", "-P6033", "-C", "-e", "select 1", "--default-auth=mysql_native_password" }; + std::vector n_auth_args = { "mysql", "-uroot", "-proot", "-h", "127.0.0.1", "-P6033", "-e", "select 1", "--default-auth=mysql_native_password" }; + + // Query the mysql server in a compressed connection + std::string result = ""; + int query_res = execvp(mysql_select_command, n_auth_cargs, result); + ok(query_res == 0 && result != "", "Native auth compressed query should be executed correctly."); + + // Now query again using a uncompressed connection + query_res = execvp(mysql_select_command, n_auth_args, result); + ok(query_res == 0 && result != "", "Native auth uncompressed query should be executed correctly."); + + // Teardown config + MYSQL_QUERY(proxysql_admin, delete_mysql_query_rule); + MYSQL_QUERY(proxysql_admin, enable_select_query_rules); + MYSQL_QUERY(proxysql_admin, load_mysql_queries_runtime); + + return exit_status(); +} diff --git a/test/tap/tests/reg_test_2793-compression-t.cpp b/test/tap/tests/reg_test_2793-compression-t.cpp new file mode 100644 index 0000000000..6d299d344b --- /dev/null +++ b/test/tap/tests/reg_test_2793-compression-t.cpp @@ -0,0 +1,59 @@ +/** + * @file test_mixed_compression-t.cpp + * @brief This test is a regression test for issue #2793. + * @version v2.1.12 + * @date 2020-05-14 + */ + +#include +#include +#include +#include +#include + +#include "tap.h" +#include "command_line.h" +#include "utils.h" + +using std::string; + +int main(int argc, char** argv) { + CommandLine cl; + + if (cl.getEnv()) { + diag("Failed to get the required environmental variables."); + return -1; + } + + plan(1); + + MYSQL* proxysql_admin = mysql_init(NULL); + MYSQL* proxysql_mysql = mysql_init(NULL); + + // Initialize connections + if (!proxysql_admin || !proxysql_mysql) { + if (!proxysql_admin) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); + } else { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); + } + return -1; + } + + // Connnect to local proxysql + if (!mysql_real_connect(proxysql_admin, "127.0.0.1", "admin", "admin", NULL, 6032, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); + return -1; + } + + // Mixed compressed / uncompressed queries test #1493 + const char* mysql_select_command = "mysql"; + std::vector cargs = { "mysql", "-uroot", "-proot", "-h", "127.0.0.1", "-P6033", "-C", "-e", "select 1" }; + + // Query the mysql server in a compressed connection + std::string result = ""; + int query_res = execvp(mysql_select_command, cargs, result); + ok(query_res == 0 && result != "", "Compressed query should be executed correctly."); + + return exit_status(); +} From a1e96362bef0d62b82ff9de134ff001c49334905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Thu, 14 May 2020 23:46:01 +0200 Subject: [PATCH 5/9] Multiple improvements on regression tests - Fixed expected number of executed tests - Removed hardcoded parameters for target servers - Removed unnecessary code - Removed unnecessary info in header comments --- .../reg_test_1493-mixed_compression-t.cpp | 30 +++++++------------ .../tap/tests/reg_test_2793-compression-t.cpp | 22 +------------- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/test/tap/tests/reg_test_1493-mixed_compression-t.cpp b/test/tap/tests/reg_test_1493-mixed_compression-t.cpp index d420c0f309..633bcbff14 100644 --- a/test/tap/tests/reg_test_1493-mixed_compression-t.cpp +++ b/test/tap/tests/reg_test_1493-mixed_compression-t.cpp @@ -1,7 +1,6 @@ /** - * @file test_mixed_compression-t.cpp + * @file reg_test_1493-mixed_compression-t.cpp * @brief This test is a regression test for issue #1493. - * @version v2.1.12 * @date 2020-05-14 */ @@ -26,23 +25,18 @@ int main(int argc, char** argv) { return -1; } - plan(1); + plan(2); MYSQL* proxysql_admin = mysql_init(NULL); - MYSQL* proxysql_mysql = mysql_init(NULL); // Initialize connections - if (!proxysql_admin || !proxysql_mysql) { - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - } else { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); - } + if (!proxysql_admin) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; } // Connnect to local proxysql - if (!mysql_real_connect(proxysql_admin, "127.0.0.1", "admin", "admin", NULL, 6032, NULL, 0)) { + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; } @@ -65,16 +59,14 @@ int main(int argc, char** argv) { MYSQL_QUERY(proxysql_admin, update_mysql_query_rules); MYSQL_QUERY(proxysql_admin, load_mysql_queries_runtime); - // Connect to mysql - if (!mysql_real_connect(proxysql_mysql, "127.0.0.1", "root", "root", NULL, 6033, NULL, CLIENT_COMPRESS)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); - return -1; - } - // Mixed compressed / uncompressed queries test #1493 const char* mysql_select_command = "mysql"; - std::vector n_auth_cargs = { "mysql", "-uroot", "-proot", "-h", "127.0.0.1", "-P6033", "-C", "-e", "select 1", "--default-auth=mysql_native_password" }; - std::vector n_auth_args = { "mysql", "-uroot", "-proot", "-h", "127.0.0.1", "-P6033", "-e", "select 1", "--default-auth=mysql_native_password" }; + std::string tg_port = std::string("-P") + std::to_string(cl.port); + std::string name = std::string("-u") + cl.username; + std::string pass = std::string("-p") + cl.password; + + std::vector n_auth_cargs = { "mysql", name.c_str(), pass.c_str(), "-h", cl.host, tg_port.c_str(), "-C", "-e", "select 1", "--default-auth=mysql_native_password" }; + std::vector n_auth_args = { "mysql", name.c_str(), pass.c_str(), "-h", cl.host, tg_port.c_str(), "-e", "select 1", "--default-auth=mysql_native_password" }; // Query the mysql server in a compressed connection std::string result = ""; diff --git a/test/tap/tests/reg_test_2793-compression-t.cpp b/test/tap/tests/reg_test_2793-compression-t.cpp index 6d299d344b..6744f798f0 100644 --- a/test/tap/tests/reg_test_2793-compression-t.cpp +++ b/test/tap/tests/reg_test_2793-compression-t.cpp @@ -1,7 +1,6 @@ /** - * @file test_mixed_compression-t.cpp + * @file reg_test_2793-compression-t.cpp * @brief This test is a regression test for issue #2793. - * @version v2.1.12 * @date 2020-05-14 */ @@ -27,25 +26,6 @@ int main(int argc, char** argv) { plan(1); - MYSQL* proxysql_admin = mysql_init(NULL); - MYSQL* proxysql_mysql = mysql_init(NULL); - - // Initialize connections - if (!proxysql_admin || !proxysql_mysql) { - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - } else { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); - } - return -1; - } - - // Connnect to local proxysql - if (!mysql_real_connect(proxysql_admin, "127.0.0.1", "admin", "admin", NULL, 6032, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - // Mixed compressed / uncompressed queries test #1493 const char* mysql_select_command = "mysql"; std::vector cargs = { "mysql", "-uroot", "-proot", "-h", "127.0.0.1", "-P6033", "-C", "-e", "select 1" }; From 025ae40efa7b182a4981c635b9206420537b17fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Thu, 14 May 2020 23:52:22 +0200 Subject: [PATCH 6/9] Removed unnecessary comment from test file --- test/tap/tests/reg_test_2793-compression-t.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/tap/tests/reg_test_2793-compression-t.cpp b/test/tap/tests/reg_test_2793-compression-t.cpp index 6744f798f0..9ea9c0076d 100644 --- a/test/tap/tests/reg_test_2793-compression-t.cpp +++ b/test/tap/tests/reg_test_2793-compression-t.cpp @@ -26,7 +26,6 @@ int main(int argc, char** argv) { plan(1); - // Mixed compressed / uncompressed queries test #1493 const char* mysql_select_command = "mysql"; std::vector cargs = { "mysql", "-uroot", "-proot", "-h", "127.0.0.1", "-P6033", "-C", "-e", "select 1" }; From 27aea669cb6e8cb9d3a5a8238011ef7863d15f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Fri, 15 May 2020 11:07:17 +0200 Subject: [PATCH 7/9] Improved helper function to avoid stalling when max PIPE size is exceeded --- test/tap/tap/utils.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/tap/tap/utils.cpp b/test/tap/tap/utils.cpp index ea029e735e..33a0cbde2f 100644 --- a/test/tap/tap/utils.cpp +++ b/test/tap/tap/utils.cpp @@ -172,25 +172,25 @@ int execvp(const std::string& cmd, const std::vector& argv, std::st close(CHILD_WRITE_FD); close(CHILD_WRITE_ERR); - waitpid(child_pid, &err, 0); - if (err == 0) { // Read from child’s stdout - count = read(PARENT_READ_FD, buffer, sizeof(buffer) - 1); + count = read(PARENT_READ_FD, buffer, sizeof(buffer)); while (count > 0) { buffer[count] = 0; result_ += buffer; - count = 0; + count = read(PARENT_READ_FD, buffer, sizeof(buffer)); } } else { // Read from child’s stderr - count = read(PARENT_READ_ERR, buffer, sizeof(buffer) - 1); + count = read(PARENT_READ_ERR, buffer, sizeof(buffer)); while (count > 0) { buffer[count] = 0; result_ += buffer; - count = 0; + count = read(PARENT_READ_ERR, buffer, sizeof(buffer)); } } + + waitpid(child_pid, &err, 0); } result = result_; From df614b85517bccd1ed0cf6139d69452010915b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Fri, 15 May 2020 11:08:36 +0200 Subject: [PATCH 8/9] Changed 'mysql client' command parameter name for tests --- test/tap/tests/reg_test_1493-mixed_compression-t.cpp | 6 +++--- test/tap/tests/reg_test_2793-compression-t.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/tap/tests/reg_test_1493-mixed_compression-t.cpp b/test/tap/tests/reg_test_1493-mixed_compression-t.cpp index 633bcbff14..9f00169c21 100644 --- a/test/tap/tests/reg_test_1493-mixed_compression-t.cpp +++ b/test/tap/tests/reg_test_1493-mixed_compression-t.cpp @@ -60,7 +60,7 @@ int main(int argc, char** argv) { MYSQL_QUERY(proxysql_admin, load_mysql_queries_runtime); // Mixed compressed / uncompressed queries test #1493 - const char* mysql_select_command = "mysql"; + const char* mysql_client = "mysql"; std::string tg_port = std::string("-P") + std::to_string(cl.port); std::string name = std::string("-u") + cl.username; std::string pass = std::string("-p") + cl.password; @@ -70,11 +70,11 @@ int main(int argc, char** argv) { // Query the mysql server in a compressed connection std::string result = ""; - int query_res = execvp(mysql_select_command, n_auth_cargs, result); + int query_res = execvp(mysql_client, n_auth_cargs, result); ok(query_res == 0 && result != "", "Native auth compressed query should be executed correctly."); // Now query again using a uncompressed connection - query_res = execvp(mysql_select_command, n_auth_args, result); + query_res = execvp(mysql_client, n_auth_args, result); ok(query_res == 0 && result != "", "Native auth uncompressed query should be executed correctly."); // Teardown config diff --git a/test/tap/tests/reg_test_2793-compression-t.cpp b/test/tap/tests/reg_test_2793-compression-t.cpp index 9ea9c0076d..6880637609 100644 --- a/test/tap/tests/reg_test_2793-compression-t.cpp +++ b/test/tap/tests/reg_test_2793-compression-t.cpp @@ -26,12 +26,12 @@ int main(int argc, char** argv) { plan(1); - const char* mysql_select_command = "mysql"; + const char* mysql_client = "mysql"; std::vector cargs = { "mysql", "-uroot", "-proot", "-h", "127.0.0.1", "-P6033", "-C", "-e", "select 1" }; // Query the mysql server in a compressed connection std::string result = ""; - int query_res = execvp(mysql_select_command, cargs, result); + int query_res = execvp(mysql_client, cargs, result); ok(query_res == 0 && result != "", "Compressed query should be executed correctly."); return exit_status(); From 61ca7c3a072b2f1b84a27c5d5af90bc6c328b08f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Mon, 18 May 2020 22:24:21 +0200 Subject: [PATCH 9/9] Remove unnecessary macros from tests compilation --- test/tap/tests/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tap/tests/Makefile b/test/tap/tests/Makefile index 99a98bed1d..8d8d7f859d 100644 --- a/test/tap/tests/Makefile +++ b/test/tap/tests/Makefile @@ -105,7 +105,7 @@ test_tokenizer-t: test_tokenizer-t.cpp $(TAP_LIBDIR)/libtap.a g++ test_tokenizer-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(MYLIBS) -lproxysql -ltap -Wl,--no-as-needed -ldl -lpthread -o test_tokenizer-t -DGITVERSION=\"$(GIT_VERSION)\" 1493_mixed_compression: reg_test_1493-mixed_compression-t.cpp - g++ -DTEST_AURORA -DDEBUG test_mixed_compression-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(OBJ) $(MYLIBS) -ltap -ldl $(STATIC_LIBS) -o reg_test_1493-mixed_compression-t -DGITVERSION=\"$(GIT_VERSION)\" + g++ -DDEBUG test_mixed_compression-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(OBJ) $(MYLIBS) -ltap -ldl $(STATIC_LIBS) -o reg_test_1493-mixed_compression-t -DGITVERSION=\"$(GIT_VERSION)\" 2793_compression: reg_test_2793-compression-t.cpp - g++ -DTEST_AURORA -DDEBUG reg_test_2793-compression-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(OBJ) $(MYLIBS) -ltap -ldl $(STATIC_LIBS) -o reg_test_2793-compression-t -DGITVERSION=\"$(GIT_VERSION)\" + g++ -DDEBUG reg_test_2793-compression-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(OBJ) $(MYLIBS) -ltap -ldl $(STATIC_LIBS) -o reg_test_2793-compression-t -DGITVERSION=\"$(GIT_VERSION)\"