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

add workdir as environment variable #2715

Merged
merged 4 commits into from
May 4, 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
16 changes: 13 additions & 3 deletions test/tap/tap/command_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using nlohmann::json;

CommandLine::CommandLine() :
host(NULL), username(NULL), password(NULL), admin_username(NULL), admin_password(NULL) {}
host(NULL), username(NULL), password(NULL), admin_username(NULL), admin_password(NULL), workdir(NULL) {}

CommandLine::~CommandLine() {
if (host)
Expand All @@ -26,11 +26,13 @@ CommandLine::~CommandLine() {
free(admin_username);
if (admin_password)
free(admin_password);
if (workdir)
free(workdir);
}

int CommandLine::parse(int argc, char** argv) {
int opt;
while ((opt = getopt(argc, argv, "ncsu:p:h:P:")) != -1) {
while ((opt = getopt(argc, argv, "ncsu:p:h:P:W:")) != -1) {
switch (opt) {
case 'c':
checksum = true;
Expand Down Expand Up @@ -59,11 +61,14 @@ int CommandLine::parse(int argc, char** argv) {
case 'U':
admin_username = strdup(optarg);
break;
case 'W':
workdir = strdup(optarg);
break;
case 'S':
admin_password = strdup(optarg);
break;
default: /* '?' */
fprintf(stderr, "Usage: %s -u username -p password -h host [ -P port ] [ -A port ] [ -U admin_username ] [ -S admin_password ] [ -c ] [ -s ] [ -n ]\n", argv[0]);
fprintf(stderr, "Usage: %s -u username -p password -h host [ -P port ] [ -A port ] [ -U admin_username ] [ -S admin_password ] [ -W workdir] [ -c ] [ -s ] [ -n ]\n", argv[0]);
return 0;
}
}
Expand Down Expand Up @@ -101,6 +106,7 @@ int CommandLine::read(const std::string& file) {
admin_port = 6032;
username = strdup("root");
password = strdup("a");
workdir = strdup("./tests/");
return 0;
}

Expand Down Expand Up @@ -152,5 +158,9 @@ int CommandLine::getEnv() {
if(env_port>0 && env_port<65536)
admin_port=env_port;

value=getenv("TAP_WORKDIR");
if(!value) return -1;
workdir = strdup(value);

return 0;
}
1 change: 1 addition & 0 deletions test/tap/tap/command_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CommandLine {
char* admin_password;
int port;
int admin_port;
char* workdir;

int read(const std::string& file);
int getEnv();
Expand Down
2 changes: 1 addition & 1 deletion test/tap/tests/select_config_file-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int main(int argc, char** argv) {

{
std::ifstream inFile;
inFile.open("./tests/proxysql_reference_select_config_file.cnf"); //open the input file
inFile.open(std::string(cl.workdir) + "/proxysql_reference_select_config_file.cnf"); //open the input file

std::stringstream strStream;
strStream << inFile.rdbuf(); //read the file
Expand Down
2 changes: 1 addition & 1 deletion test/tap/tests/set_testing-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,11 @@ void * my_conn_thread(void *arg) {

int main(int argc, char *argv[]) {
CommandLine cl;
std::string fileName("./tests/set_testing-t.csv");

if(cl.getEnv())
return exit_status();

std::string fileName(std::string(cl.workdir) + "/set_testing-t.csv");
MYSQL* mysqladmin = mysql_init(NULL);
if (!mysqladmin)
return exit_status();
Expand Down
44 changes: 41 additions & 3 deletions test/tap/tests/test_ps_large_result-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ int select_config_file(MYSQL* mysql, std::string& resultset) {

}

int restore_admin(MYSQL* mysqladmin) {
MYSQL_QUERY(mysqladmin, "load mysql query rules from disk");
MYSQL_QUERY(mysqladmin, "load mysql query rules to runtime");
MYSQL_QUERY(mysqladmin, "load mysql servers from disk");
MYSQL_QUERY(mysqladmin, "load mysql servers to runtime");
}

int main(int argc, char** argv) {
CommandLine cl;
Expand All @@ -44,7 +50,17 @@ int main(int argc, char** argv) {
return exit_status();

plan(10);
diag("Testing SELECT CONFIG FILE");
diag("Testing PS large resultset");

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

MYSQL* mysql = mysql_init(NULL);
if (!mysql)
Expand All @@ -56,6 +72,12 @@ int main(int argc, char** argv) {
return exit_status();
}

MYSQL_QUERY(mysqladmin, "delete from mysql_query_rules");
MYSQL_QUERY(mysqladmin, "load mysql query rules to runtime");

MYSQL_QUERY(mysqladmin, "delete from mysql_servers where hostgroup_id=1");
MYSQL_QUERY(mysqladmin, "load mysql servers to runtime");

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)");
Expand Down Expand Up @@ -91,13 +113,13 @@ int main(int argc, char** argv) {
q << "(" << k << ",'" << c.str() << "','" << pad.str() << "')";
}
MYSQL_QUERY(mysql, q.str().c_str());
ok(true, "%d row inserted. Waiting for possible replication on test server 30(s)", NUM_ROWS);
sleep(30);
ok(true, "%d row inserted.", NUM_ROWS);

MYSQL_STMT *stmt1 = mysql_stmt_init(mysql);
if (!stmt1)
{
ok(false, " mysql_stmt_init(), out of memory\n");
restore_admin(mysqladmin);
return exit_status();
}

Expand All @@ -106,13 +128,15 @@ int main(int argc, char** argv) {
fprintf(stderr, "Query error %s\n", mysql_error(mysql));
mysql_close(mysql);
mysql_library_end();
restore_admin(mysqladmin);
return exit_status();
}

if (mysql_stmt_execute(stmt1))
{
fprintf(stderr, " mysql_stmt_execute(), failed\n");
ok(false, " %s\n", mysql_stmt_error(stmt1));
restore_admin(mysqladmin);
return exit_status();
}
ok(true, "100 rows result stored");
Expand All @@ -135,13 +159,15 @@ int main(int argc, char** argv) {
{
fprintf(stderr, " mysql_stmt_bind_result() failed\n");
ok(false, " %s\n", mysql_stmt_error(stmt1));
restore_admin(mysqladmin);
return exit_status();
}

if (mysql_stmt_store_result(stmt1))
{
fprintf(stderr, " mysql_stmt_store_result() failed\n");
ok(false, " %s\n", mysql_stmt_error(stmt1));
restore_admin(mysqladmin);
return exit_status();
}

Expand All @@ -154,26 +180,30 @@ int main(int argc, char** argv) {
{
fprintf(stderr, " failed while closing the statement\n");
ok(false, " %s\n", mysql_error(mysql));
restore_admin(mysqladmin);
return exit_status();
}

MYSQL_STMT *stmt2 = mysql_stmt_init(mysql);
if (!stmt2)
{
ok(false, " mysql_stmt_init(), out of memory\n");
restore_admin(mysqladmin);
return exit_status();
}
query = "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";
if (mysql_stmt_prepare(stmt2,query.c_str(), query.size())) {
fprintf(stderr, "Query error %s\n", mysql_error(mysql));
mysql_close(mysql);
mysql_library_end();
restore_admin(mysqladmin);
return exit_status();
}
if (mysql_stmt_execute(stmt2))
{
fprintf(stderr, " mysql_stmt_execute(), failed\n");
ok(false, " %s\n", mysql_stmt_error(stmt2));
restore_admin(mysqladmin);
return exit_status();
}
ok(true, "4GB resultset stored");
Expand Down Expand Up @@ -251,13 +281,15 @@ int main(int argc, char** argv) {
{
fprintf(stderr, " mysql_stmt_bind_result() failed\n");
ok(false, " %s\n", mysql_stmt_error(stmt2));
restore_admin(mysqladmin);
return exit_status();
}

if (mysql_stmt_store_result(stmt2))
{
fprintf(stderr, " mysql_stmt_store_result() failed\n");
ok(false, " %s\n", mysql_stmt_error(stmt2));
restore_admin(mysqladmin);
return exit_status();
}

Expand All @@ -273,6 +305,7 @@ int main(int argc, char** argv) {
{
fprintf(stderr, " failed while closing the statement\n");
ok(false, " %s\n", mysql_error(mysql));
restore_admin(mysqladmin);
return exit_status();
}

Expand All @@ -282,6 +315,7 @@ int main(int argc, char** argv) {
if (!stmt3)
{
ok(false, " mysql_stmt_init(), out of memory\n");
restore_admin(mysqladmin);
return exit_status();
}

Expand All @@ -292,6 +326,7 @@ int main(int argc, char** argv) {
fprintf(stderr, "Query error %s\n", mysql_error(mysql));
mysql_close(mysql);
mysql_library_end();
restore_admin(mysqladmin);
return exit_status();
}

Expand Down Expand Up @@ -379,12 +414,15 @@ int main(int argc, char** argv) {
{
fprintf(stderr, " failed while closing the statement\n");
ok(false, " %s\n", mysql_error(mysql));
restore_admin(mysqladmin);
return exit_status();
}

if (str_data32)
free(str_data32);

restore_admin(mysqladmin);

mysql_close(mysql);
mysql_library_end();

Expand Down