Test for large result fix

pull/2506/head
Valentin Rakush 6 years ago
parent 868f70903d
commit 515c2e1100

@ -74,13 +74,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 || 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 || 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
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
tests: basic-t set_character_set-t charset_unsigned_int-t select_config_file-t sqlite3-t test_set_character_results-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
testgalera: galera_1_timeout_count galera_2_timeout_no_count
testaurora: aurora
@ -102,6 +102,9 @@ select_config_file-t: select_config_file-t.cpp $(TAP_LIBDIR)/libtap.a
test_set_character_results-t: test_set_character_results-t.cpp $(TAP_LIBDIR)/libtap.a
g++ test_set_character_results-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(MYLIBS) -ltap -lssl -lcrypto -ldl -lpthread -o test_set_character_results-t
test_ps_large_result-t: test_ps_large_result-t.cpp $(TAP_LIBDIR)/libtap.a
g++ test_ps_large_result-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(MYLIBS) -ltap -lssl -lcrypto -ldl -lpthread -o test_ps_large_result-t
galera_1_timeout_count: galera_1_timeout_count.cpp $(TAP_LIBDIR)/libtap.a
g++ -DTEST_GALERA -DDEBUG galera_1_timeout_count.cpp ../tap/SQLite3_Server.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(OBJ) $(MYLIBS) -ltap -ldl -o galera_1_timeout_count -DGITVERSION=\"$(GIT_VERSION)\"

@ -0,0 +1,161 @@
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <unistd.h>
#include <random>
#include <fstream>
#include <sstream>
#include <string>
#include <mysql.h>
#include "tap.h"
#include "command_line.h"
#include "utils.h"
const int NUM_ROWS=10000;
int select_config_file(MYSQL* mysql, std::string& resultset) {
if (mysql_query(mysql, "select config file")) {
fprintf(stderr, "File %s, line %d, Error: %s\n",
__FILE__, __LINE__, mysql_error(mysql));
return exit_status();
}
MYSQL_RES *result;
MYSQL_ROW row;
result = mysql_store_result(mysql);
if (result) {
row = mysql_fetch_row(result);
resultset = row[0];
mysql_free_result(result);
} else {
fprintf(stderr, "error\n");
}
}
int main(int argc, char** argv) {
CommandLine cl;
if(cl.getEnv())
return exit_status();
plan(9);
diag("Testing SELECT CONFIG FILE");
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, "drop database if exists test");
MYSQL_QUERY(mysql, "create database if not exists test");
MYSQL_QUERY(mysql, "create table if not exists test.t (i int)");
MYSQL_QUERY(mysql, "CREATE TABLE if not exists test.sbtest1 (`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `k` int(10) unsigned NOT NULL DEFAULT '0', `c` char(120) NOT NULL DEFAULT '', `pad` char(60) NOT NULL DEFAULT '', PRIMARY KEY (`id`), KEY `k_1` (`k`))");
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_int_distribution<int> dist(0.0, 9.0);
std::stringstream q;
q << "INSERT INTO test.sbtest1 (k, c, pad) values ";
bool put_comma = false;
for (int i=0; i<NUM_ROWS; ++i) {
int k = dist(mt);
std::stringstream c;
for (int j=0; j<10; j++) {
for (int k=0; k<11; k++) {
c << dist(mt);
}
if (j<9)
c << "-";
}
std::stringstream pad;
for (int j=0; j<5; j++) {
for (int k=0; k<11; k++) {
pad << dist(mt);
}
if (j<4)
pad << "-";
}
if (put_comma) q << ",";
if (!put_comma) put_comma=true;
q << "(" << k << ",'" << c.str() << "','" << pad.str() << "')";
}
MYSQL_QUERY(mysql, q.str().c_str());
ok(true, "%d row inserted", NUM_ROWS);
/* Test case #1. */
if (mysql_query(mysql, "SELECT id FROM test.sbtest1 LIMIT 100")) {
fprintf(stderr, "Query error %s\n", mysql_error(mysql));
mysql_close(mysql);
mysql_library_end();
return exit_status();
}
MYSQL_RES* result = mysql_store_result(mysql);
ok(true, "100 rows result stored");
MYSQL_ROW row;
while ((row = mysql_fetch_row(result)))
{
unsigned long *lengths;
lengths = mysql_fetch_lengths(result);
}
mysql_free_result(result);
ok(true, "Fetched 100 rows");
/* Test case #2. */
if (mysql_query(mysql, "SELECT t1.id id1, t1.k k1, t1.c c1, t1.pad pad1, t2.id id2, t2.k k2, t2.c c2, t2.pad pad2 FROM test.sbtest1 t1 JOIN test.sbtest1 t2 LIMIT 10000000")) {
fprintf(stderr, "Query error %s\n", mysql_error(mysql));
mysql_close(mysql);
mysql_library_end();
return exit_status();
}
result = mysql_store_result(mysql);
ok(true, "4GB Result stored");
int num_rows = mysql_num_rows(result);
ok(num_rows==10000000, "Fetch 10000000 rows");
while ((row = mysql_fetch_row(result)))
{
unsigned long *lengths;
lengths = mysql_fetch_lengths(result);
}
mysql_free_result(result);
ok(true, "Fetched 4GB");
/* Test case #3. */
if (mysql_query(mysql, "SELECT id, k, REPEAT(c,100+ROUND(RAND()*200000)) FROM test.sbtest1 LIMIT 10")) {
fprintf(stderr, "Query error %s\n", mysql_error(mysql));
mysql_close(mysql);
mysql_library_end();
return exit_status();
}
result = mysql_store_result(mysql);
ok(true, "4GB Result stored");
num_rows = mysql_num_rows(result);
ok(num_rows==10, "Fetch 10 rows");
while ((row = mysql_fetch_row(result)))
{
unsigned long *lengths;
lengths = mysql_fetch_lengths(result);
}
mysql_free_result(result);
ok(true, "Fetched large rows");
mysql_close(mysql);
mysql_library_end();
return exit_status();
}
Loading…
Cancel
Save