Skip to content

Commit

Permalink
Merge pull request #4287 from sysown/v2.x-change_user_compression
Browse files Browse the repository at this point in the history
V2.x change user compression #4158
  • Loading branch information
renecannao authored Jul 14, 2023
2 parents b908323 + c025ec0 commit 4c77e09
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/mysql_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2779,9 +2779,12 @@ int MySQL_Connection::async_send_simple_command(short event, char *stmt, unsigne

void MySQL_Connection::reset() {
bool old_no_multiplex_hg = get_status(STATUS_MYSQL_CONNECTION_NO_MULTIPLEX_HG);
bool old_compress = get_status(STATUS_MYSQL_CONNECTION_COMPRESSION);
status_flags=0;
// reconfigure STATUS_MYSQL_CONNECTION_NO_MULTIPLEX_HG
set_status(old_no_multiplex_hg,STATUS_MYSQL_CONNECTION_NO_MULTIPLEX_HG);
// reconfigure STATUS_MYSQL_CONNECTION_COMPRESSION
set_status(old_compress,STATUS_MYSQL_CONNECTION_COMPRESSION);
reusable=true;
options.last_set_autocommit=-1; // never sent

Expand Down
123 changes: 123 additions & 0 deletions test/tap/tests/reg_test_4158_change_user-t.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/**
* @file reg_test_4158_change_user-t.cpp
* @brief This test verifies COM_CHANGE_USER and COM_RESET_CONNECTION with compression
*
* @details It run COM_CHANGE_USER and COM_RESET_CONNECTION with compression.
* This seems broken in 2.x (not sure yet in which version the regression was
* first introduced), while working fine in 1.4
*/

#include "mysql.h"

#include "proxysql_utils.h"
#include "tap.h"
#include "utils.h"

#include <unistd.h>
#include <iostream>

using std::string;

//#include "json.hpp"
//using nlohmann::json;


using namespace std;

int loop1 = 3;
int loop2 = 3;

CommandLine cl;

int work_mysql() {
MYSQL* proxy = mysql_init(NULL);
if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, CLIENT_COMPRESS)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy));
return EXIT_FAILURE;
}

for (int j=0; j < loop1 ; j++) {
diag("We run multiple queries just to verify that the connection is still healthy after the firstone");
for (int i=0; i < loop2 ; i++) {
MYSQL_QUERY_T(proxy, "SELECT CONNECTION_ID()");
MYSQL_RES* myres;
myres = mysql_store_result(proxy);
int nr = mysql_num_rows(myres);
ok(nr == 1, "Rows returned: %d" , nr);
mysql_free_result(myres);
}
int rb;
diag("Running mysql_reset_connection()");
rb = mysql_reset_connection(proxy);
ok(rb == 0 , "mysql_reset_connection(): %s", (rb == 0 ? "OK" : mysql_error(proxy)));
diag("Running mysql_change_user()");
rb = mysql_change_user(proxy, cl.username, cl.password, NULL);
ok(rb == 0 , "mysql_change_user(): %s", (rb == 0 ? "OK" : mysql_error(proxy)));
}
mysql_close(proxy);
return 0;
}

void * work(void *arg) {
work_mysql(); // this return an int
return NULL;
}

int run_funct_timeout(void *(*start_routine)(void *), int timeout) {
// we run the test on a separate thread because we have a built-in timeout
pthread_t thread_id;
if (pthread_create(&thread_id, NULL, start_routine, NULL)) {
fprintf(stderr, "Error calling pthread_create()");
return EXIT_FAILURE;
}

if (timeout != 0) {
int tr = 0;
while (timeout != 0) {
sleep(1);
tr = pthread_tryjoin_np(thread_id, NULL);
if (tr == 0) {
timeout = 0;
} else {
timeout--;
diag("Waiting up to %d seconds", timeout);
}
}
if (tr =! 0) {
return EXIT_FAILURE;
}
} else {
// if timeout == 0 , the timeout is disabled
// This is useful during debugging, while running the TAP test in gdb
diag("Built-in timeout DISABLED");
pthread_join(thread_id, NULL);
return 0;
}
return 0;
}
int main(int, char**) {

plan(loop1 * (loop2 + 2));

if (cl.getEnv()) {
diag("Failed to get the required environmental variables.");
return EXIT_FAILURE;
}

/*
// PLACEHOLDER
MYSQL* admin = mysql_init(NULL);
if (!mysql_real_connect(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(admin));
return EXIT_FAILURE;
}
MYSQL_QUERY_T(admin, "LOAD MYSQL VARIABLES TO RUNTIME");
mysql_close(admin);
*/

run_funct_timeout(work, 10);

return exit_status();
}

0 comments on commit 4c77e09

Please sign in to comment.