From 646e927570b9eb16c99dc957b51b6e1c990de9bd Mon Sep 17 00:00:00 2001 From: val Date: Sun, 26 Apr 2020 20:24:03 +0000 Subject: [PATCH 1/2] transaction_isolation test --- test/tap/tests/Makefile | 9 +- ..._default_value_transaction_isolation-t.cpp | 91 +++++++++++++++++++ 2 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 test/tap/tests/test_default_value_transaction_isolation-t.cpp diff --git a/test/tap/tests/Makefile b/test/tap/tests/Makefile index 43124fcde0..52d866f1db 100644 --- a/test/tap/tests/Makefile +++ b/test/tap/tests/Makefile @@ -75,13 +75,13 @@ all: tests .PHONY: clean clean: - rm -f basic-t set_character_set-t charset_unsigned_int-t select_config_file-t sqlite3-t galera_1_timeout_count galera_2_timeout_no_count aurora test_set_character_results-t test_ps_large_result-t set_testing-t test_firewall-t || true + rm -f basic-t set_character_set-t charset_unsigned_int-t select_config_file-t sqlite3-t galera_1_timeout_count galera_2_timeout_no_count aurora test_set_character_results-t test_ps_large_result-t set_testing-t test_firewall-t test_default_value_transaction_isolation-t || true OPT=-O2 -SRC=basic-t.cpp set_character_set-t.cpp charset_unsigned_int-t.cpp select_config_file-t.cpp sqlite3-t.cpp galera_1_timeout_count.cpp galera_2_timeout_no_count.cpp aurora.cpp test_set_character_results-t.cpp test_ps_large_result-t.cpp set_testing-t.cpp test_firewall-t.cpp +SRC=basic-t.cpp set_character_set-t.cpp charset_unsigned_int-t.cpp select_config_file-t.cpp sqlite3-t.cpp galera_1_timeout_count.cpp galera_2_timeout_no_count.cpp aurora.cpp test_set_character_results-t.cpp test_ps_large_result-t.cpp set_testing-t.cpp test_firewall-t.cpp test_default_value_transaction_isolation-t.cpp -tests: basic-t set_character_set-t charset_unsigned_int-t select_config_file-t sqlite3-t test_set_character_results-t test_ps_large_result-t set_testing-t test_firewall-t +tests: basic-t set_character_set-t charset_unsigned_int-t select_config_file-t sqlite3-t test_set_character_results-t test_ps_large_result-t set_testing-t test_firewall-t test_default_value_transaction_isolation-t testgalera: galera_1_timeout_count galera_2_timeout_no_count testaurora: aurora @@ -120,3 +120,6 @@ aurora: aurora.cpp $(TAP_LIBDIR)/libtap.a set_testing-t: set_testing-t.cpp $(TAP_LIBDIR)/libtap.a g++ set_testing-t.cpp -Wall $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(MYLIBS) -ltap -pthread -O0 -ggdb -ldl -lssl -lcrypto -o set_testing-t + +test_default_value_transaction_isolation-t: test_default_value_transaction_isolation-t.cpp $(TAP_LIBDIR)/libtap.a + g++ test_default_value_transaction_isolation-t.cpp -Wall $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(MYLIBS) -ltap -pthread -O0 -ggdb -ldl -lssl -lcrypto -o test_default_value_transaction_isolation-t diff --git a/test/tap/tests/test_default_value_transaction_isolation-t.cpp b/test/tap/tests/test_default_value_transaction_isolation-t.cpp new file mode 100644 index 0000000000..cca5d20806 --- /dev/null +++ b/test/tap/tests/test_default_value_transaction_isolation-t.cpp @@ -0,0 +1,91 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include "tap.h" +#include "command_line.h" +#include "utils.h" + +int main(int argc, char** argv) { + CommandLine cl; + + if(cl.getEnv()) + return exit_status(); + + plan(3); + diag("Testing default value for session varable transaction isolation"); + + MYSQL* mysqladmin = mysql_init(NULL); + if (!mysqladmin) + return exit_status(); + + if (!mysql_real_connect(mysqladmin, 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(mysqladmin)); + return exit_status(); + } + + // Set default non-existing value for transaction isolation level + MYSQL_QUERY(mysqladmin, "set mysql-default_isolation_level='non-existing-value-1'"); + MYSQL_QUERY(mysqladmin, "load mysql variables to runtime"); + + MYSQL* mysql_1 = mysql_init(NULL); + if (!mysql_1) + return exit_status(); + + if (!mysql_real_connect(mysql_1, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "Failed to connect to database: Error: %s\n", + mysql_error(mysql_1)); + return exit_status(); + } + MYSQL_QUERY(mysql_1, "select 1"); + MYSQL_RES* result = mysql_store_result(mysql_1); + ok(mysql_num_rows(result) == 1, "Select statement should be executed on connection 1"); + mysql_free_result(result); + + MYSQL* mysql_2 = mysql_init(NULL); + if (!mysql_2) + return exit_status(); + + if (!mysql_real_connect(mysql_2, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "Failed to connect to database: Error: %s\n", + mysql_error(mysql_2)); + return exit_status(); + } + MYSQL_QUERY(mysql_2, "select 1"); + result = mysql_store_result(mysql_2); + ok(mysql_num_rows(result) == 1, "Select statement should be executed on connection 1"); + mysql_free_result(result); + + // Change default non-existing value for transaction isolation level + MYSQL_QUERY(mysqladmin, "set mysql-default_isolation_level='non-existing-value-2'"); + MYSQL_QUERY(mysqladmin, "load mysql variables to runtime"); + + // Try third connection with different default value of the session variable + MYSQL* mysql_3 = mysql_init(NULL); + if (!mysql_3) + return exit_status(); + + if (!mysql_real_connect(mysql_3, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "Failed to connect to database: Error: %s\n", + mysql_error(mysql_3)); + return exit_status(); + } + MYSQL_QUERY(mysql_3, "select 1"); + result = mysql_store_result(mysql_3); + ok(mysql_num_rows(result) == 1, "Select statement should be executed on connection 1"); + mysql_free_result(result); + + mysql_close(mysql_3); + mysql_close(mysql_2); + mysql_close(mysql_1); + mysql_close(mysqladmin); + + return exit_status(); +} + From f92360713905dd8a11a0333f6f8dbe82af80ce27 Mon Sep 17 00:00:00 2001 From: val Date: Mon, 27 Apr 2020 14:06:43 +0000 Subject: [PATCH 2/2] reset hash value --- lib/mysql_connection.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index bdb917dd67..48ce4a73b2 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -387,6 +387,7 @@ MySQL_Connection::~MySQL_Connection() { if (variables[i].value) { free(variables[i].value); variables[i].value = NULL; + var_hash[i] = 0; } } @@ -2264,6 +2265,7 @@ void MySQL_Connection::reset() { if (variables[i].value) { free(variables[i].value); variables[i].value = NULL; + var_hash[i] = 0; } }