Cleanup and fixes on set_testing TAP tests

pull/3702/head
René Cannaò 5 years ago
parent 5b37f25cfa
commit 74ab11b84f

@ -225,11 +225,11 @@ void * my_conn_thread(void *arg) {
}
if (k == mysql_vars.end())
fprintf(stderr, "Variable %s->%s in mysql resultset was not found.\nmysql data : %s\nproxysql data: %s\ncsv data %s\n",
diag("Variable %s->%s in mysql resultset was not found.\nmysql data : %s\nproxysql data: %s\ncsv data %s\n",
el.value().dump().c_str(), el.key().c_str(), mysql_vars.dump().c_str(), proxysql_vars.dump().c_str(), vars.dump().c_str());
if (s == proxysql_vars["conn"].end())
fprintf(stderr, "Variable %s->%s in proxysql resultset was not found.\nmysql data : %s\nproxysql data: %s\ncsv data %s\n",
diag("Variable %s->%s in proxysql resultset was not found.\nmysql data : %s\nproxysql data: %s\ncsv data %s\n",
el.value().dump().c_str(), el.key().c_str(), mysql_vars.dump().c_str(), proxysql_vars.dump().c_str(), vars.dump().c_str());
bool verified_special_sqlmode = false;
@ -302,11 +302,11 @@ void * my_conn_thread(void *arg) {
} else {
__sync_fetch_and_add(&g_failed, 1);
testPassed = false;
fprintf(stderr, "Test failed for this case %s->%s.\n\nmysql data [%lu]: %s\n\n proxysql data [%lu]: %s\n\n csv data %s\n\n\n",
el.value().dump().c_str(), el.key().c_str(),
mysql_vars.size(), mysql_vars.dump().c_str(),
proxysql_vars.size(), proxysql_vars.dump().c_str(),
vars.dump().c_str());
diag("Test failed for this case %s->%s.\n\nmysql data [%lu]: %s\n\n proxysql data [%lu]: %s\n\n csv data %s\n\n\n",
el.value().dump(2).c_str(), el.key().c_str(),
mysql_vars.size(), mysql_vars.dump(2).c_str(),
proxysql_vars["conn"].size(), proxysql_vars["conn"].dump(2).c_str(),
vars.dump(2).c_str());
diag("FAILED FOR: connections mysql[%p] proxysql[%s], thread_id [%lu], command [%s]", mysql, paddress.c_str(), mysql->thread_id, testCases[r2].command.c_str());
//ok(testPassed, "connections mysql[%p] proxysql[%s], thread_id [%lu], command [%s]", mysql, paddress.c_str(), mysql->thread_id, testCases[r2].command.c_str());
// In case of failing test, exit completely.
@ -337,38 +337,11 @@ int main(int argc, char *argv[]) {
std::string fileName2(std::string(cl.workdir) + "/set_testing-240.csv");
MYSQL* mysql = mysql_init(NULL);
if (!mysql)
if (detect_version(cl, is_mariadb, is_cluster) != 0) {
diag("Cannot detect MySQL version");
return exit_status();
if (!mysql_real_connect(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(mysql));
return exit_status();
}
MYSQL_QUERY(mysql, "select @@version");
MYSQL_RES *result = mysql_store_result(mysql);
MYSQL_ROW row;
while ((row = mysql_fetch_row(result)))
{
if (strstr(row[0], "Maria")) {
is_mariadb = true;
}
else {
is_mariadb = false;
}
char* first_dash = strstr(row[0], "-");
if (!first_dash || !strstr(first_dash+1, "-")) {
is_cluster = false;
} else {
// FIXME: we need a better version detection
is_cluster = true;
}
}
mysql_free_result(result);
mysql_close(mysql);
num_threads = 10;
queries_per_connections = 10;
count = 10;

@ -21,83 +21,6 @@
#include "utils.h"
#include "command_line.h"
/*
std::vector<std::string> split(const std::string& s, char delimiter)
{
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter))
{
tokens.push_back(token);
}
return tokens;
}
using nlohmann::json;
struct TestCase {
std::string command;
json expected_vars;
json reset_vars;
};
std::vector<TestCase> testCases;
#define MAX_LINE 1024
int readTestCases(const std::string& fileName) {
FILE* fp = fopen(fileName.c_str(), "r");
if (!fp) return 0;
char buf[MAX_LINE], col1[MAX_LINE], col2[MAX_LINE], col3[MAX_LINE] = {0};
int n = 0;
for(;;) {
if (fgets(buf, sizeof(buf), fp) == NULL) break;
n = sscanf(buf, " \"%[^\"]\", \"%[^\"]\", \"%[^\"]\"", col1, col2, col3);
if (n == 0) break;
char *p = col2;
while(*p++) if(*p == '\'') *p = '\"';
json vars = json::parse(col2);
p = col3;
while(col3[0] != 0 && *p++) if(*p == '\'') *p = '\"';
json reset_vars;
if (p != col3) {
reset_vars = json::parse(col3);
}
testCases.push_back({col1, vars, reset_vars});
}
fclose(fp);
return 1;
}
unsigned long long monotonic_time() {
struct timespec ts;
//clock_gettime(CLOCK_MONOTONIC_COARSE, &ts); // this is faster, but not precise
clock_gettime(CLOCK_MONOTONIC, &ts);
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
}
struct cpu_timer
{
cpu_timer() {
begin = monotonic_time();
}
~cpu_timer()
{
unsigned long long end = monotonic_time();
std::cerr << double( end - begin ) / 1000000 << " secs.\n" ;
begin=end-begin;
};
unsigned long long begin;
};
*/
std::string bn = "";
int queries_per_connections=1;
unsigned int num_threads=1;
@ -187,7 +110,7 @@ void * my_conn_thread(void *arg) {
for (j=0; j<queries; j++) {
int fr = fastrand();
int r1=fr%count;
int r2=fastrand()%testCases.size();
int r2=rand()%testCases.size();
if (j%queries_per_connections==0) {
mysql=mysqlconns[r1];
@ -420,36 +343,13 @@ int main(int argc, char *argv[]) {
std::cerr << bn << ": " << q << std::endl;
MYSQL_QUERY(mysqladmin, q.c_str());
}
MYSQL* mysql = mysql_init(NULL);
if (!mysql)
return exit_status();
if (!mysql_real_connect(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(mysql));
if (detect_version(cl, is_mariadb, is_cluster) != 0) {
diag("Cannot detect MySQL version");
return exit_status();
}
MYSQL_QUERY(mysql, "select @@version");
MYSQL_RES *result = mysql_store_result(mysql);
MYSQL_ROW row;
while ((row = mysql_fetch_row(result)))
{
if (strstr(row[0], "Maria")) {
is_mariadb = true;
}
else {
is_mariadb = false;
}
char* first_dash = strstr(row[0], "-");
if (!first_dash || !strstr(first_dash+1, "-")) {
is_cluster = false;
} else {
is_cluster = true;
}
}
mysql_free_result(result);
mysql_close(mysql);
num_threads = 10;
queries = 1000;

@ -22,6 +22,7 @@
#include <iostream>
#include <fstream>
#include <mutex>
#include <algorithm>
#include "json.hpp"
#include "re2/re2.h"
@ -227,11 +228,11 @@ void * my_conn_thread(void *arg) {
}
if (k == mysql_vars.end())
fprintf(stderr, "Variable %s->%s in mysql resultset was not found.\nmysql data : %s\nproxysql data: %s\ncsv data %s\n",
diag("Variable %s->%s in mysql resultset was not found.\nmysql data : %s\nproxysql data: %s\ncsv data %s\n",
el.value().dump().c_str(), el.key().c_str(), mysql_vars.dump().c_str(), proxysql_vars.dump().c_str(), vars.dump().c_str());
if (s == proxysql_vars["conn"].end())
fprintf(stderr, "Variable %s->%s in proxysql resultset was not found.\nmysql data : %s\nproxysql data: %s\ncsv data %s\n",
diag("Variable %s->%s in proxysql resultset was not found.\nmysql data : %s\nproxysql data: %s\ncsv data %s\n",
el.value().dump().c_str(), el.key().c_str(), mysql_vars.dump().c_str(), proxysql_vars.dump().c_str(), vars.dump().c_str());
bool verified_special_sqlmode = false;
@ -247,7 +248,11 @@ void * my_conn_thread(void *arg) {
std::string e_val { el.value() };
std::string k_val { k.value() };
std::string s_val { s.value() };
if (el.value() == s.value()) { // but same in proxysql
if (e_val != s_val) {
// try to replace " with '
std::replace( e_val.begin(), e_val.end(), '"', '\'');
}
if (e_val == s_val) { // but same in proxysql
std::string str_val { el.value() };
if (strcasecmp(str_val.c_str(), "TRADITIONAL")==0) {
if (k.value() == "STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION") {
@ -304,11 +309,11 @@ void * my_conn_thread(void *arg) {
} else {
__sync_fetch_and_add(&g_failed, 1);
testPassed = false;
fprintf(stderr, "Test failed for this case %s->%s.\n\nmysql data [%lu]: %s\n\n proxysql data [%lu]: %s\n\n csv data %s\n\n\n",
el.value().dump().c_str(), el.key().c_str(),
mysql_vars.size(), mysql_vars.dump().c_str(),
proxysql_vars.size(), proxysql_vars.dump().c_str(),
vars.dump().c_str());
diag("Test failed for this case %s->%s.\n\nmysql data [%lu]: %s\n\n proxysql data [%lu]: %s\n\n csv data %s\n\n\n",
el.value().dump(2).c_str(), el.key().c_str(),
mysql_vars.size(), mysql_vars.dump(2).c_str(),
proxysql_vars["conn"].size(), proxysql_vars["conn"].dump(2).c_str(),
vars.dump(2).c_str());
diag("FAILED FOR: connections mysql[%p] proxysql[%s], thread_id [%lu], command [%s]", mysql, paddress.c_str(), mysql->thread_id, testCases[r2].command.c_str());
//ok(testPassed, "connections mysql[%p] proxysql[%s], thread_id [%lu], command [%s]", mysql, paddress.c_str(), mysql->thread_id, testCases[r2].command.c_str());
// In case of failing test, exit completely.
@ -329,6 +334,7 @@ void * my_conn_thread(void *arg) {
}
int main(int argc, char *argv[]) {
CommandLine cl;
@ -339,38 +345,12 @@ int main(int argc, char *argv[]) {
std::string fileName(std::string(cl.workdir) + "/set_testing-t.csv");
MYSQL* mysql = mysql_init(NULL);
if (!mysql)
return exit_status();
if (!mysql_real_connect(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(mysql));
return exit_status();
}
MYSQL_QUERY(mysql, "select @@version");
MYSQL_RES *result = mysql_store_result(mysql);
MYSQL_ROW row;
while ((row = mysql_fetch_row(result)))
{
if (strstr(row[0], "Maria")) {
is_mariadb = true;
}
else {
is_mariadb = false;
}
char* first_dash = strstr(row[0], "-");
if (!first_dash || !strstr(first_dash+1, "-")) {
is_cluster = false;
} else {
// FIXME: we need a better version detection
is_cluster = true;
}
if (detect_version(cl, is_mariadb, is_cluster) != 0) {
diag("Cannot detect MySQL version");
return exit_status();
}
mysql_free_result(result);
mysql_close(mysql);
num_threads = 10;
queries_per_connections = 10;
count = 10;

@ -444,3 +444,39 @@ bool check_session_track_gtids(const std::string& expVal, const std::string& sVa
return res;
}
int detect_version(CommandLine& cl, bool& is_mariadb, bool& is_cluster) {
MYSQL* mysql = mysql_init(NULL);
if (!mysql)
return 1;
if (!mysql_real_connect(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(mysql));
return 1;
}
MYSQL_QUERY(mysql, "select @@version");
MYSQL_RES *result = mysql_store_result(mysql);
MYSQL_ROW row;
while ((row = mysql_fetch_row(result)))
{
if (strstr(row[0], "Maria")) {
is_mariadb = true;
}
else {
is_mariadb = false;
}
}
mysql_free_result(result);
MYSQL_QUERY(mysql, "SHOW VARIABLES LIKE 'wsrep_sync_wait'");
result = mysql_store_result(mysql);
unsigned long long nr = mysql_num_rows(result);
if (nr == 0) {
is_cluster = false;
} else {
is_cluster = true;
}
mysql_free_result(result);
mysql_close(mysql);
return 0;
}

Loading…
Cancel
Save