Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transaction_isolation test #2701

Merged
merged 2 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/mysql_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ MySQL_Connection::~MySQL_Connection() {
if (variables[i].value) {
free(variables[i].value);
variables[i].value = NULL;
var_hash[i] = 0;
}
}

Expand Down Expand Up @@ -2264,6 +2265,7 @@ void MySQL_Connection::reset() {
if (variables[i].value) {
free(variables[i].value);
variables[i].value = NULL;
var_hash[i] = 0;
}
}

Expand Down
9 changes: 6 additions & 3 deletions test/tap/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
91 changes: 91 additions & 0 deletions test/tap/tests/test_default_value_transaction_isolation-t.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <unistd.h>

#include <string>
#include <sstream>
#include <mysql.h>

#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();
}