Add format attribute to test functions, fix resulting errors

Fixes mysqlmon_failover_stress.
This commit is contained in:
Esa Korhonen
2018-09-12 14:10:04 +02:00
parent e1f2b81734
commit d65d815b99
10 changed files with 15 additions and 14 deletions

View File

@ -115,7 +115,7 @@ void test2(TestConnections& test)
test.add_result(strcmp(buffer1, buffer2) == 0, "Expected results to differ"); test.add_result(strcmp(buffer1, buffer2) == 0, "Expected results to differ");
test.add_result(strcmp(buffer2, server_id) != 0, test.add_result(strcmp(buffer2, server_id) != 0,
"Expected prepare 2 to go to the master (%s) but it's %s", "Expected prepare 2 to go to the master (%s) but it's %s",
server_id[0], buffer2); server_id, buffer2);
} }
void test3(TestConnections& test) void test3(TestConnections& test)
@ -168,7 +168,7 @@ void test3(TestConnections& test)
sprintf(server_id, "%d", test.repl->get_server_id(0)); sprintf(server_id, "%d", test.repl->get_server_id(0));
test.add_result(strcmp(buffer, server_id) != 0, test.add_result(strcmp(buffer, server_id) != 0,
"Expected the execute inside a transaction to go to the master (%s) but it's %s", "Expected the execute inside a transaction to go to the master (%s) but it's %s",
server_id[0], buffer); server_id, buffer);
} }
int main(int argc, char** argv) int main(int argc, char** argv)

View File

@ -175,7 +175,7 @@ int check_longblob_data(TestConnections* Test, MYSQL * conn, unsigned long chunk
{ {
if ((int)data[y] != y) if ((int)data[y] != y)
{ {
Test->add_result(1, "expected %d, got %d", data[y], y); Test->add_result(1, "expected %lu, got %d", data[y], y);
break; break;
} }
} }

View File

@ -82,7 +82,7 @@ int main(int argc, char *argv[])
{ {
Test->set_timeout(15); Test->set_timeout(15);
Test->add_result(mysql_change_user(Test->maxscales->conn_rwsplit[0], "user", "pass2", (char *) "test"), Test->add_result(mysql_change_user(Test->maxscales->conn_rwsplit[0], "user", "pass2", (char *) "test"),
"change_user failed! %", mysql_error(Test->maxscales->conn_rwsplit[0])); "change_user failed! %s", mysql_error(Test->maxscales->conn_rwsplit[0]));
Test->add_result(mysql_change_user(Test->maxscales->conn_rwsplit[0], Test->maxscales->user_name, Test->maxscales->password, Test->add_result(mysql_change_user(Test->maxscales->conn_rwsplit[0], Test->maxscales->user_name, Test->maxscales->password,
(char *) "test"), "change_user failed! %s", mysql_error(Test->maxscales->conn_rwsplit[0])); (char *) "test"), "change_user failed! %s", mysql_error(Test->maxscales->conn_rwsplit[0]));
} }

View File

@ -47,7 +47,7 @@ int main(int argc, char** argv)
std::accumulate(errors.begin(), errors.end(), std::string(), std::accumulate(errors.begin(), errors.end(), std::string(),
[](const std::string &a, const std::string &b) { [](const std::string &a, const std::string &b) {
return a + b + " "; return a + b + " ";
})); }).c_str());
test.tprintf("Dropping databases..."); test.tprintf("Dropping databases...");
for (auto db : db_list) for (auto db : db_list)

View File

@ -33,7 +33,8 @@ int main(int argc, char** argv)
test.maxscales->connect(); test.maxscales->connect();
MYSQL_STMT* stmt = mysql_stmt_init(test.maxscales->conn_rwsplit[0]); MYSQL_STMT* stmt = mysql_stmt_init(test.maxscales->conn_rwsplit[0]);
test.expect(mysql_stmt_prepare(stmt, sqlstr, strlen(sqlstr)) != 0, "Prepare should fail in 2.2 but not hang", test.expect(mysql_stmt_prepare(stmt, sqlstr, strlen(sqlstr)) != 0,
"Prepare should fail in 2.2 but not hang. Error: %s",
mysql_stmt_error(stmt)); mysql_stmt_error(stmt));
mysql_stmt_close(stmt); mysql_stmt_close(stmt);

View File

@ -59,7 +59,7 @@ void do_query(TestConnections *test, bool should_fail)
"Query was successful when failure was expected." : "Query was successful when failure was expected." :
"Query failed when success was expected."; "Query failed when success was expected.";
test->add_result(failed == should_fail, msg); test->add_result(failed == should_fail, "%s", msg);
test->maxscales->close_maxscale_connections(0); test->maxscales->close_maxscale_connections(0);
test->stop_timeout(); test->stop_timeout();

View File

@ -38,7 +38,7 @@ void do_query(TestConnections *test, bool should_fail)
"Query was successful when failure was expected." : "Query was successful when failure was expected." :
"Query failed when success was expected."; "Query failed when success was expected.";
test->add_result(failed == should_fail, msg); test->add_result(failed == should_fail, "%s", msg);
test->maxscales->close_maxscale_connections(0); test->maxscales->close_maxscale_connections(0);
test->stop_timeout(); test->stop_timeout();

View File

@ -552,7 +552,7 @@ void run(TestConnections& test)
} }
else else
{ {
test.expect(false, "Unexpected master id: %d"); test.expect(false, "Unexpected master id: %d", master_id);
} }
} }

View File

@ -75,15 +75,15 @@ void *query_thread1( void *ptr )
{ {
MYSQL *conn1 = data->Test->maxscales->open_rwsplit_connection(0); MYSQL *conn1 = data->Test->maxscales->open_rwsplit_connection(0);
data->Test->add_result(mysql_errno(conn1), data->Test->add_result(mysql_errno(conn1),
"Error opening RWsplit conn, thread num is %d, iteration %d, error is: %s\n", "Error opening RWsplit conn, thread num is %d, iteration %li, error is: %s\n",
data->thread_id, data->i, mysql_error(conn1)); data->thread_id, data->i, mysql_error(conn1));
MYSQL *conn2 = data->Test->maxscales->open_readconn_master_connection(0); MYSQL *conn2 = data->Test->maxscales->open_readconn_master_connection(0);
data->Test->add_result(mysql_errno(conn2), data->Test->add_result(mysql_errno(conn2),
"Error opening ReadConn master conn, thread num is %d, iteration %d, error is: %s\n", data->thread_id, "Error opening ReadConn master conn, thread num is %d, iteration %li, error is: %s\n", data->thread_id,
data->i, mysql_error(conn2)); data->i, mysql_error(conn2));
MYSQL *conn3 = data->Test->maxscales->open_readconn_slave_connection(0); MYSQL *conn3 = data->Test->maxscales->open_readconn_slave_connection(0);
data->Test->add_result(mysql_errno(conn3), data->Test->add_result(mysql_errno(conn3),
"Error opening ReadConn master conn, thread num is %d, iteration %d, error is: %s\n", data->thread_id, "Error opening ReadConn master conn, thread num is %d, iteration %li, error is: %s\n", data->thread_id,
data->i, mysql_error(conn3)); data->i, mysql_error(conn3));
// USE test here is a hack to prevent Maxscale from failure; should be removed when fixed // USE test here is a hack to prevent Maxscale from failure; should be removed when fixed
if (conn1 != NULL) if (conn1 != NULL)

View File

@ -252,10 +252,10 @@ public:
* @param result 0 if step PASSED * @param result 0 if step PASSED
* @param format ... message to pring if result is not 0 * @param format ... message to pring if result is not 0
*/ */
void add_result(bool result, const char *format, ...); void add_result(bool result, const char *format, ...) __attribute__((format(printf, 3, 4)));
/** Same as add_result() but inverted */ /** Same as add_result() but inverted */
void expect(bool result, const char *format, ...); void expect(bool result, const char *format, ...) __attribute__((format(printf, 3, 4)));
/** /**
* @brief ReadEnv Reads all Maxscale and Master/Slave and Galera setups info from environmental variables * @brief ReadEnv Reads all Maxscale and Master/Slave and Galera setups info from environmental variables