diff --git a/maxscale-system-test/fwf.cpp b/maxscale-system-test/fwf.cpp index aa076107b..53356b31b 100644 --- a/maxscale-system-test/fwf.cpp +++ b/maxscale-system-test/fwf.cpp @@ -51,42 +51,61 @@ int main(int argc, char *argv[]) sprintf(pass_file, "%s/fw/pass%d", test_dir, i); sprintf(deny_file, "%s/fw/deny%d", test_dir, i); - Test->tprintf("Pass file: %s\n", pass_file); - Test->tprintf("Deny file: %s\n", deny_file); + + if (Test->verbose) + { + Test->tprintf("Pass file: %s", pass_file); + Test->tprintf("Deny file: %s", deny_file); + } file = fopen(pass_file, "r"); if (file != NULL) { - Test->tprintf("********** Trying queries that should be OK ********** \n"); + if (Test->verbose) + { + Test->tprintf("********** Trying queries that should be OK ********** "); + } while (fgets(sql, sizeof(sql), file)) { if (strlen(sql) > 1) { - Test->tprintf("%s", sql); - local_result += execute_query(Test->conn_rwsplit, sql); + if (Test->verbose) + { + Test->tprintf("%s", sql); + } + int rv = execute_query(Test->conn_rwsplit, sql); + Test->add_result(rv, "Query should succeed: %s", sql); + local_result += rv; } } fclose(file); } else { - Test->add_result(1, "Error opening query file\n"); + Test->add_result(1, "Error opening query file"); } file = fopen(deny_file, "r"); if (file != NULL) { - Test->tprintf("********** Trying queries that should FAIL ********** \n"); + if (Test->verbose) + { + Test->tprintf("********** Trying queries that should FAIL ********** "); + } while (fgets(sql, sizeof(sql), file)) { Test->set_timeout(180); if (strlen(sql) > 1) { - Test->tprintf("%s", sql); - execute_query(Test->conn_rwsplit, sql); + if (Test->verbose) + { + Test->tprintf("%s", sql); + } + execute_query_silent(Test->conn_rwsplit, sql); if (mysql_errno(Test->conn_rwsplit) != 1141) { - Test->tprintf("Query succeded, but fail expected, errono is %d\n", mysql_errno(Test->conn_rwsplit)); + Test->tprintf("Expected 1141, Access Denied but got %d, %s instead: %s", + mysql_errno(Test->conn_rwsplit), mysql_error(Test->conn_rwsplit), sql); local_result++; } } @@ -95,15 +114,16 @@ int main(int argc, char *argv[]) } else { - Test->add_result(1, "Error opening query file\n"); + Test->add_result(1, "Error opening query file"); } - if (local_result != 0) + + if (local_result) { - Test->add_result(1, "********** rules%d test FAILED\n", i); + Test->add_result(1, "********** rules%d test FAILED", i); } else { - Test->tprintf("********** rules%d test PASSED\n", i); + Test->tprintf("********** rules%d test PASSED", i); } mysql_close(Test->conn_rwsplit); @@ -113,11 +133,18 @@ int main(int argc, char *argv[]) Test->stop_maxscale(); // Test for at_times clause - Test->tprintf("Trying at_times clause\n"); + if (Test->verbose) + { + Test->tprintf("Trying at_times clause"); + } copy_rules(Test, (char *) "rules_at_time", rules_dir); - Test->tprintf("DELETE quries without WHERE clause will be blocked during next 2 minutes\n"); - Test->tprintf("Put time to rules.txt: %s\n", str); + + if (Test->verbose) + { + Test->tprintf("DELETE quries without WHERE clause will be blocked during next 2 minutes"); + Test->tprintf("Put time to rules.txt: %s", str); + } Test->ssh_maxscale(false, "start_time=`date +%%T`; stop_time=` date --date " "\"now +2 mins\" +%%T`; %s sed -i \"s/###time###/$start_time-$stop_time/\" %s/rules/rules.txt", Test->maxscale_access_sudo, Test->maxscale_access_homedir); @@ -125,13 +152,16 @@ int main(int argc, char *argv[]) Test->start_maxscale(); Test->connect_rwsplit(); - Test->tprintf("Trying 'DELETE FROM t1' and expecting FAILURE\n"); - execute_query(Test->conn_rwsplit, "DELETE FROM t1"); + Test->tprintf("Trying 'DELETE FROM t1' and expecting FAILURE"); + execute_query_silent(Test->conn_rwsplit, "DELETE FROM t1"); + if (mysql_errno(Test->conn_rwsplit) != 1141) { - Test->add_result(1, "Query succeded, but fail expected, errono is %d\n", mysql_errno(Test->conn_rwsplit)); + Test->add_result(1, "Query succeded, but fail expected, errono is %d", mysql_errno(Test->conn_rwsplit)); } - Test->tprintf("Waiting 3 minutes and trying 'DELETE FROM t1', expecting OK\n"); + + Test->tprintf("Waiting 3 minutes and trying 'DELETE FROM t1', expecting OK"); + Test->stop_timeout(); sleep(180); Test->set_timeout(180); @@ -140,20 +170,20 @@ int main(int argc, char *argv[]) mysql_close(Test->conn_rwsplit); Test->stop_maxscale(); - Test->tprintf("Trying limit_queries clause\n"); - Test->tprintf("Copying rules to Maxscale machine: %s\n", str); + Test->tprintf("Trying limit_queries clause"); + Test->tprintf("Copying rules to Maxscale machine: %s", str); copy_rules(Test, (char *) "rules_limit_queries", rules_dir); Test->start_maxscale(); Test->connect_rwsplit(); - printf("Trying 10 quries as fast as possible\n"); + Test->tprintf("Trying 10 quries as fast as possible"); for (i = 0; i < 10; i++) { - Test->add_result(execute_query(Test->conn_rwsplit, "SELECT * FROM t1"), "%d -query failed\n", i); + Test->add_result(execute_query_silent(Test->conn_rwsplit, "SELECT * FROM t1"), "%d -query failed", i); } - Test->tprintf("Expecting failures during next 5 seconds\n"); + Test->tprintf("Expecting failures during next 5 seconds"); time_t start_time_clock = time(NULL); timeval t1, t2; @@ -169,38 +199,42 @@ int main(int argc, char *argv[]) } while ((execute_query_silent(Test->conn_rwsplit, "SELECT * FROM t1") != 0) && (elapsedTime < 10)); - Test->tprintf("Quries were blocked during %f (using clock_gettime())\n", elapsedTime); - Test->tprintf("Quries were blocked during %lu (using time())\n", time(NULL) - start_time_clock); + Test->tprintf("Quries were blocked during %f (using clock_gettime())", elapsedTime); + Test->tprintf("Quries were blocked during %lu (using time())", time(NULL) - start_time_clock); + if ((elapsedTime > 6) or (elapsedTime < 4)) { - Test->add_result(1, "Queries were blocked during wrong time\n"); + Test->add_result(1, "Queries were blocked during wrong time"); } Test->set_timeout(180); - printf("Trying 20 quries, 1 query / second\n"); + printf("Trying 20 quries, 1 query / second"); for (i = 0; i < 20; i++) { sleep(1); - Test->add_result(execute_query(Test->conn_rwsplit, "SELECT * FROM t1"), "query failed\n"); - Test->tprintf("%d ", i); + Test->add_result(execute_query_silent(Test->conn_rwsplit, "SELECT * FROM t1"), "query failed"); + if (Test->verbose) + { + Test->tprintf("%d ", i); + } } - Test->tprintf("\n"); + Test->set_timeout(180); - Test->tprintf("Stopping Maxscale\n"); + Test->tprintf("Stopping Maxscale"); Test->stop_maxscale(); - Test->tprintf("Trying rules with syntax error\n"); - Test->tprintf("Copying rules to Maxscale machine: %s\n", str); + Test->tprintf("Trying rules with syntax error"); + Test->tprintf("Copying rules to Maxscale machine: %s", str); copy_rules(Test, (char *) "rules_syntax_error", rules_dir); - Test->tprintf("Starting Maxscale\n"); + Test->tprintf("Starting Maxscale"); Test->start_maxscale(); Test->connect_rwsplit(); - Test->tprintf("Trying to connectt to Maxscale when 'rules' has syntax error, expecting failures\n"); + Test->tprintf("Trying to connect to Maxscale when 'rules' has syntax error, expecting failures"); if (execute_query(Test->conn_rwsplit, "SELECT * FROM t1") == 0) { - Test->add_result(1, "Rule has syntax error, but query OK\n"); + Test->add_result(1, "Rule has syntax error, but query OK"); } Test->check_maxscale_processes(0);