Rename TestConnections::assert() to TestConnections::expect()

Allows the including of <assert.h>.
This commit is contained in:
Johan Wikman 2018-09-10 10:24:46 +03:00
parent bcacdf9358
commit 6279ab350c
38 changed files with 117 additions and 117 deletions

View File

@ -28,7 +28,7 @@ int main(int argc, char** argv)
// Do the select inside a transacttion so that it gets routed to the master
test.try_query(test.maxscales->conn_rwsplit[0], "BEGIN");
test.assert(execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT id FROM test.t1", "2") == 0,
test.expect(execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT id FROM test.t1", "2") == 0,
"Table should contain one row with value 2");
test.try_query(test.maxscales->conn_rwsplit[0], "COMMIT");

View File

@ -85,7 +85,7 @@ void different_packet_size(TestConnections* Test, bool binlog)
char* event = create_event_size(size);
conn = connect_to_serv(Test, binlog);
Test->assert(execute_query_silent(conn, event) == 0, "Query should succeed");
Test->expect(execute_query_silent(conn, event) == 0, "Query should succeed");
free(event);
execute_query_silent(conn, (char *) "DELETE FROM test.large_event");
mysql_close(conn);

View File

@ -159,7 +159,7 @@ bool generate_traffic_and_check(TestConnections& test, MYSQL* conn, int insert_c
mysql_query(conn, SELECT);
MYSQL_RES *res = mysql_store_result(conn);
test.assert(res != NULL, "Query did not return a result set");
test.expect(res != NULL, "Query did not return a result set");
if (res)
{
@ -172,14 +172,14 @@ bool generate_traffic_and_check(TestConnections& test, MYSQL* conn, int insert_c
int value_read = strtol(row[0], NULL, 0);
if (value_read != expected_val)
{
test.assert(false, "Query returned %d when %d was expected", value_read, expected_val);
test.expect(false, "Query returned %d when %d was expected", value_read, expected_val);
rval = false;
break;
}
expected_val++;
}
int num_rows = expected_val;
test.assert(num_rows == inserts, "Query returned %d rows when %d rows were expected",
test.expect(num_rows == inserts, "Query returned %d rows when %d rows were expected",
num_rows, inserts);
if (num_rows != inserts)
{

View File

@ -33,7 +33,7 @@ void reset_replication(TestConnections& test)
test.maxscales->wait_for_monitor(2);
master_id = get_master_server_id(test);
cout << "Master server id is now back to " << master_id << endl;
test.assert(master_id == 1, "Switchover back to server1 failed");
test.expect(master_id == 1, "Switchover back to server1 failed");
}
get_output(test);
StringSet node_states;
@ -43,7 +43,7 @@ void reset_replication(TestConnections& test)
servername << "server" << i;
node_states = test.get_server_status(servername.str().c_str());
bool states_ok = (node_states.find("Slave") != node_states.end());
test.assert(states_ok, "Server %d is not replicating.", i);
test.expect(states_ok, "Server %d is not replicating.", i);
}
}
@ -63,7 +63,7 @@ void check_test_1(TestConnections& test, int node0_id)
get_output(test);
int master_id = get_master_server_id(test);
cout << "Master server id is " << master_id << endl;
test.assert(master_id > 0 && master_id != node0_id, "Master did not change or no master detected.");
test.expect(master_id > 0 && master_id != node0_id, "Master did not change or no master detected.");
if (test.global_result == 0)
{
check(test);
@ -98,7 +98,7 @@ void check_test_2(TestConnections& test)
cout << "Master server id is " << master_id << endl;
bool success = (master_id > 0 &&
(master_id == test.repl->get_server_id(2) || master_id == test.repl->get_server_id(3)));
test.assert(success, WRONG_SLAVE);
test.expect(success, WRONG_SLAVE);
if (test.global_result == 0)
{
check(test);
@ -109,7 +109,7 @@ void check_test_2(TestConnections& test)
test.maxscales->wait_for_monitor(2);
get_output(test);
StringSet node_states = test.get_server_status("server2");
test.assert(node_states.find("Slave") != node_states.end(), "Server 2 is not replicating.");
test.expect(node_states.find("Slave") != node_states.end(), "Server 2 is not replicating.");
if (test.global_result == 0)
{
reset_replication(test);
@ -167,7 +167,7 @@ void check_test_3(TestConnections& test)
// Because servers have been restarted, redo connections.
test.repl->connect();
cout << "Master server id is " << master_id << endl;
test.assert(master_id > 0 && master_id == test.repl->get_server_id(3), WRONG_SLAVE);
test.expect(master_id > 0 && master_id == test.repl->get_server_id(3), WRONG_SLAVE);
print_gtids(test);
reset_replication(test);

View File

@ -240,11 +240,11 @@ void test_connecting(TestConnections& test,
if (!could_connect && should_be_able_to)
{
test.assert(false, "%s@%s should have been able to connect, but wasn't.", zUser, zHost);
test.expect(false, "%s@%s should have been able to connect, but wasn't.", zUser, zHost);
}
else if (could_connect && !should_be_able_to)
{
test.assert(false, "%s@%s should NOT have been able to connect, but was.", zUser, zHost);
test.expect(false, "%s@%s should NOT have been able to connect, but was.", zUser, zHost);
}
else
{
@ -348,7 +348,7 @@ int main(int argc, char** argv)
}
else
{
test.assert(false, "MaxScale node does not have at least one IP-address.");
test.expect(false, "MaxScale node does not have at least one IP-address.");
}
return test.global_result;

View File

@ -9,22 +9,22 @@ int main(int argc, char** argv)
TestConnections test(argc, argv);
int rc = test.maxscales->ssh_node_f(0, false, "maxctrl help list servers");
test.assert(rc == 0, "`help list servers` should work");
test.expect(rc == 0, "`help list servers` should work");
rc = test.maxscales->ssh_node_f(0, false, "maxctrl --tsv list servers|grep 'Master, Running'");
test.assert(rc == 0, "`list servers` should return at least one row with: Master, Running");
test.expect(rc == 0, "`list servers` should return at least one row with: Master, Running");
rc = test.maxscales->ssh_node_f(0, false, "maxctrl set server server1 maintenance");
test.assert(rc == 0, "`set server` should work");
test.expect(rc == 0, "`set server` should work");
rc = test.maxscales->ssh_node_f(0, false, "maxctrl --tsv list servers|grep 'Maintenance'");
test.assert(rc == 0, "`list servers` should return at least one row with: Maintanance");
test.expect(rc == 0, "`list servers` should return at least one row with: Maintanance");
rc = test.maxscales->ssh_node_f(0, false, "maxctrl clear server server1 maintenance");
test.assert(rc == 0, "`clear server` should work");
test.expect(rc == 0, "`clear server` should work");
rc = test.maxscales->ssh_node_f(0, false, "maxctrl --tsv list servers|grep 'Maintenance'");
test.assert(rc != 0, "`list servers` should have no rows with: Maintanance");
test.expect(rc != 0, "`list servers` should have no rows with: Maintanance");
test.check_maxscale_alive();
return test.global_result;

View File

@ -43,7 +43,7 @@ int main(int argc, char** argv)
}
test.tprintf("Done!");
test.assert(errors.empty(), "None of the queries should fail: %s",
test.expect(errors.empty(), "None of the queries should fail: %s",
std::accumulate(errors.begin(), errors.end(), std::string(),
[](const std::string &a, const std::string &b) {
return a + b + " ";

View File

@ -33,7 +33,7 @@ void run(TestConnections& test)
init(test);
MYSQL* pMysql = mysql_init(NULL);
test.assert(pMysql, "Could not create MYSQL handle.");
test.expect(pMysql, "Could not create MYSQL handle.");
const char* zUser = test.maxscales->user_name;
const char* zPassword = test.maxscales->password;
@ -57,7 +57,7 @@ void run(TestConnections& test)
}
else
{
test.assert(false, "Could not connect to MaxScale.");
test.expect(false, "Could not connect to MaxScale.");
}
}
@ -84,17 +84,17 @@ int main(int argc, char* argv[])
}
else
{
test.assert(false, "Could not connect to RWS.");
test.expect(false, "Could not connect to RWS.");
}
}
else
{
test.assert(false, "Could not start MaxScale.");
test.expect(false, "Could not start MaxScale.");
}
}
else
{
test.assert(false, "Could not copy masking file to MaxScale node.");
test.expect(false, "Could not copy masking file to MaxScale node.");
}
return test.global_result;

View File

@ -33,7 +33,7 @@ int main(int argc, char** argv)
test.check_maxscale_alive();
int rc = test.maxscales->ssh_node_f(0, true, "grep 'version_string' /var/lib/maxscale/maxscale.cnf.d/RW-Split-Router.cnf");
test.assert(rc == 0, "Generated configuration should have version_string defined and MaxScale should ignore it.");
test.expect(rc == 0, "Generated configuration should have version_string defined and MaxScale should ignore it.");
test.maxscales->ssh_node_f(0, true, "maxadmin alter service RW-Split-Router enable_root_user=false");
@ -41,7 +41,7 @@ int main(int argc, char** argv)
test.check_maxscale_alive();
rc = test.maxscales->ssh_node_f(0, true, "grep 'version_string' /var/lib/maxscale/maxscale.cnf.d/RW-Split-Router.cnf");
test.assert(rc != 0, "Generated configuration should not have version_string defined.");
test.expect(rc != 0, "Generated configuration should not have version_string defined.");
return test.global_result;
}

View File

@ -65,7 +65,7 @@ int main(int argc, char** argv)
find_field(test.repl->nodes[0], query.c_str(), "connections", master_connections);
find_field(test.repl->nodes[1], query.c_str(), "connections", slave_connections);
test.assert(strcmp(master_connections, slave_connections) == 0,
test.expect(strcmp(master_connections, slave_connections) == 0,
"Master and slave shoud have the same amount of connections: %s != %s",
master_connections, slave_connections);

View File

@ -23,7 +23,7 @@ int main(int argc, char** argv)
cout << "Setting variable @a to 123" << endl;
mysql_query(test.maxscales->conn_rwsplit[0], "SET @a = 123");
int rc = execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @a", "123");
test.assert(rc == 0, "Text protocol should return 123 as the value of @a");
test.expect(rc == 0, "Text protocol should return 123 as the value of @a");
cout << "Preparing and executing " << NUM_STMT << " prepared statements" << endl;
for (int i = 0; i < NUM_STMT && test.global_result == 0; i++)

View File

@ -45,16 +45,16 @@ void run_test(TestConnections& test, TestCase test_case)
if (mysql_stmt_prepare(stmt, query.c_str(), query.size()))
{
test.assert(false, "Prepared statement failure: %s", mysql_stmt_error(stmt));
test.expect(false, "Prepared statement failure: %s", mysql_stmt_error(stmt));
}
cout << test_case.name << endl;
test.assert(test_case.func(test.maxscales->conn_rwsplit[0], stmt, bind), "Test '%s' failed",
test.expect(test_case.func(test.maxscales->conn_rwsplit[0], stmt, bind), "Test '%s' failed",
test_case.name.c_str());
mysql_stmt_close(stmt);
test.assert(mysql_query(test.maxscales->conn_rwsplit[0], "SELECT 1") == 0, "Normal queries should work");
test.expect(mysql_query(test.maxscales->conn_rwsplit[0], "SELECT 1") == 0, "Normal queries should work");
test.maxscales->disconnect();
}

View File

@ -46,16 +46,16 @@ int main(int argc, char* argv[])
test.set_timeout(30);
test.assert(mysql_stmt_prepare(stmt, query.c_str(), query.size()) == 0,
test.expect(mysql_stmt_prepare(stmt, query.c_str(), query.size()) == 0,
"Prepared statement failure: %s", mysql_stmt_error(stmt));
test.assert(mysql_stmt_bind_param(stmt, &bind.bind) == 0,
test.expect(mysql_stmt_bind_param(stmt, &bind.bind) == 0,
"Bind failure: %s", mysql_stmt_error(stmt));
test.assert(mysql_stmt_execute(stmt) == 0,
test.expect(mysql_stmt_execute(stmt) == 0,
"Execute failure: %s", mysql_stmt_error(stmt));
mysql_stmt_close(stmt);
test.assert(mysql_query(test.maxscales->conn_rwsplit[0], "SELECT 1") == 0, "Normal queries should work");
test.expect(mysql_query(test.maxscales->conn_rwsplit[0], "SELECT 1") == 0, "Normal queries should work");
test.maxscales->disconnect();
return test.global_result;

View File

@ -33,7 +33,7 @@ int main(int argc, char** argv)
test.maxscales->connect();
MYSQL_STMT* stmt = mysql_stmt_init(test.maxscales->conn_rwsplit[0]);
test.assert(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",
mysql_stmt_error(stmt));
mysql_stmt_close(stmt);

View File

@ -79,7 +79,7 @@ int main(int argc, char** argv)
TestConnections test(argc, argv);
test.maxscales->connect();
test.assert(test_long_data(test.maxscales->conn_rwsplit[0], 123456), "Test should work");
test.expect(test_long_data(test.maxscales->conn_rwsplit[0], 123456), "Test should work");
test.maxscales->disconnect();
return test.global_result;

View File

@ -18,9 +18,9 @@ void double_cursor(TestConnections& test, MYSQL* conn)
MYSQL_STMT* stmt1 = mysql_stmt_init(conn);
const char* query = "SELECT id FROM test.t1";
int rc = mysql_stmt_prepare(stmt1, query, strlen(query));
test.assert(rc == 0, "First prepare should work: %s %s", mysql_stmt_error(stmt1), mysql_error(conn));
test.expect(rc == 0, "First prepare should work: %s %s", mysql_stmt_error(stmt1), mysql_error(conn));
unsigned long type = CURSOR_TYPE_READ_ONLY;
test.assert(mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, &type) == 0,
test.expect(mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, &type) == 0,
"Set of first attribute should work: %s %s",
mysql_stmt_error(stmt1), mysql_error(conn));
@ -30,26 +30,26 @@ void double_cursor(TestConnections& test, MYSQL* conn)
bind[0].buffer = &id;
mysql_stmt_bind_result(stmt1, bind);
test.assert(mysql_stmt_execute(stmt1) == 0, "Execute of first statement should work: %s %s",
test.expect(mysql_stmt_execute(stmt1) == 0, "Execute of first statement should work: %s %s",
mysql_stmt_error(stmt1), mysql_error(conn));
test.assert(mysql_stmt_fetch(stmt1) == 0, "First fetch should work: %s %s",
test.expect(mysql_stmt_fetch(stmt1) == 0, "First fetch should work: %s %s",
mysql_stmt_error(stmt1), mysql_error(conn));
MYSQL_STMT* stmt2 = mysql_stmt_init(conn);
rc = mysql_stmt_prepare(stmt2, query, strlen(query));
test.assert(rc == 0, "Second prepare should work: %s %s", mysql_stmt_error(stmt2), mysql_error(conn));
test.assert(mysql_stmt_attr_set(stmt2, STMT_ATTR_CURSOR_TYPE, &type) == 0,
test.expect(rc == 0, "Second prepare should work: %s %s", mysql_stmt_error(stmt2), mysql_error(conn));
test.expect(mysql_stmt_attr_set(stmt2, STMT_ATTR_CURSOR_TYPE, &type) == 0,
"Set of second attribute should work: %s %s",
mysql_stmt_error(stmt2), mysql_error(conn));
mysql_stmt_bind_result(stmt2, bind);
test.assert(mysql_stmt_execute(stmt2) == 0, "Execute of second statement should work: %s %s",
test.expect(mysql_stmt_execute(stmt2) == 0, "Execute of second statement should work: %s %s",
mysql_stmt_error(stmt2), mysql_error(conn));
test.assert(mysql_stmt_fetch(stmt2) == 0, "Second fetch should work: %s %s", mysql_stmt_error(stmt2),
test.expect(mysql_stmt_fetch(stmt2) == 0, "Second fetch should work: %s %s", mysql_stmt_error(stmt2),
mysql_error(conn));
mysql_stmt_reset(stmt2);
test.assert(mysql_stmt_fetch(stmt1) == 0, "Third fetch should work: %s %s", mysql_stmt_error(stmt1),
test.expect(mysql_stmt_fetch(stmt1) == 0, "Third fetch should work: %s %s", mysql_stmt_error(stmt1),
mysql_error(conn));
mysql_stmt_close(stmt1);

View File

@ -11,9 +11,9 @@ int main(int argc, char** argv)
TestConnections test(argc, argv);
int rc = test.maxscales->ssh_node_f(0, true, "maxctrl alter monitor MySQL-Monitor not_a_parameter not_a_value|grep Error");
test.assert(rc == 0, "Altering unknown parameter should cause an error");
test.expect(rc == 0, "Altering unknown parameter should cause an error");
rc = test.maxscales->ssh_node_f(0, true, "maxctrl alter monitor MySQL-Monitor ignore_external_masters on_sunday_afternoons|grep Error");
test.assert(rc == 0, "Invalid parameter value should cause an error");
test.expect(rc == 0, "Invalid parameter value should cause an error");
return test.global_result;
}

View File

@ -29,12 +29,12 @@ void run(TestConnections& test, MYSQL* pMysql)
if (mysql_query(pMysql, "show eventTimes") == 0)
{
MYSQL_RES* pResult = mysql_store_result(pMysql);
test.assert(pResult, "Executing 'show eventTimes' returned no result.");
test.expect(pResult, "Executing 'show eventTimes' returned no result.");
if (pResult)
{
int nFields = mysql_field_count(pMysql);
test.assert(nFields == 3, "Expected 3 fields, got %d.", nFields);
test.expect(nFields == 3, "Expected 3 fields, got %d.", nFields);
MYSQL_ROW row;
while ((row = mysql_fetch_row(pResult)) != NULL)
@ -47,9 +47,9 @@ void run(TestConnections& test, MYSQL* pMysql)
int64_t nEvents_queued = strtoll(row[1], NULL, 0);
int64_t nEvents_executed = strtoll(row[2], NULL, 0);
test.assert(nEvents_queued >= 0 && nEvents_queued < 100,
test.expect(nEvents_queued >= 0 && nEvents_queued < 100,
"Suspiciously large number of 'No. Events Queued'.");
test.assert(nEvents_executed >= 0 && nEvents_executed < 100,
test.expect(nEvents_executed >= 0 && nEvents_executed < 100,
"Suspiciously large number of 'No. Events Executed'.");
}
@ -58,7 +58,7 @@ void run(TestConnections& test, MYSQL* pMysql)
}
else
{
test.assert(false, "Executing 'show eventTimes' failed: %s", mysql_error(pMysql));
test.expect(false, "Executing 'show eventTimes' failed: %s", mysql_error(pMysql));
}
}
@ -71,7 +71,7 @@ int main(int argc, char* argv[])
const char* zMaxScale_host = test.maxscales->ip(0);
MYSQL* pMysql = open_conn_no_db(PORT, zMaxScale_host, USER, PASSWD);
test.assert(pMysql, "Could not connect to maxinfo on MaxScale.");
test.expect(pMysql, "Could not connect to maxinfo on MaxScale.");
if (pMysql)
{

View File

@ -23,15 +23,15 @@ string get_server_id(TestConnections& test, MYSQL* pMysql)
if (rv == 0)
{
MYSQL_RES* pResult = mysql_store_result(pMysql);
test.assert(pResult, "Could not store result.");
test.expect(pResult, "Could not store result.");
if (pResult)
{
unsigned int n = mysql_field_count(pMysql);
test.assert(n == 1, "Unexpected number of fields.");
test.expect(n == 1, "Unexpected number of fields.");
MYSQL_ROW pzRow = mysql_fetch_row(pResult);
test.assert(pzRow, "Returned row was NULL.");
test.expect(pzRow, "Returned row was NULL.");
if (pzRow)
{
@ -79,7 +79,7 @@ int main(int argc, char** argv)
string slave_id = get_server_id(test, test.maxscales->conn_slave[0]);
test.tprintf("Server id: %s", slave_id.c_str());
test.assert(slave_id != master_id, "Expected something else but %s", master_id.c_str());
test.expect(slave_id != master_id, "Expected something else but %s", master_id.c_str());
return test.global_result;
}

View File

@ -11,7 +11,7 @@ int main(int argc, char** argv)
TestConnections test(argc, argv);
test.maxscales->ssh_node_f(0, true, "maxctrl alter maxscale auth_connect_timeout 10");
test.assert(test.maxscales->restart() == 0, "Restarting MaxScale after modification "
test.expect(test.maxscales->restart() == 0, "Restarting MaxScale after modification "
"of global parameters should work");
return test.global_result;

View File

@ -35,7 +35,7 @@ int main(int argc, char** argv)
test.maxscales->access_homedir[0]);
// Make sure the hidden configuration is not read and that MaxScale starts up
test.assert(test.maxscales->restart_maxscale() == 0, "Starting MaxScale should succeed");
test.expect(test.maxscales->restart_maxscale() == 0, "Starting MaxScale should succeed");
test.maxscales->ssh_node_f(0, true, "rm -r /etc/maxscale.cnf.d/");
remove("hidden.cnf");

View File

@ -13,7 +13,7 @@ int main(int argc, char** argv)
test.repl->sync_slaves();
MYSQL* conn = open_conn(test.maxscales->rwsplit_port[0], test.maxscales->IP[0], "insert_only", "insert_only", false);
test.assert(mysql_errno(conn) == 0, "User without SELECT privileges should be allowed to connect");
test.expect(mysql_errno(conn) == 0, "User without SELECT privileges should be allowed to connect");
mysql_close(conn);
execute_query(test.repl->nodes[0], "DROP USER 'insert_only'@'%%'");

View File

@ -45,19 +45,19 @@ int main(int argc, char *argv[])
auto slave = [&](const char* name)
{
static StringSet slave{"Slave", "Running"};
test.assert(status(name) == slave, "'%s' should be a slave", name);
test.expect(status(name) == slave, "'%s' should be a slave", name);
};
auto master = [&](const char* name)
{
static StringSet master{"Master", "Running"};
test.assert(status(name) == master, "'%s' should be the master", name);
test.expect(status(name) == master, "'%s' should be the master", name);
};
auto down = [&](const char* name)
{
static StringSet down{"Down"};
test.assert(status(name) == down, "'%s' should be down", name);
test.expect(status(name) == down, "'%s' should be down", name);
};
auto block = [&](int node)

View File

@ -36,15 +36,15 @@ int main(int argc, char** argv)
test.tprintf("Connect with a user that has a default role");
MYSQL* conn = open_conn_db(test.maxscales->rwsplit_port[0], test.maxscales->IP[0], "my_db", "test", "test");
test.assert(mysql_errno(conn) == 0, "Connection failed: %s", mysql_error(conn));
test.expect(mysql_errno(conn) == 0, "Connection failed: %s", mysql_error(conn));
char value[100] {};
find_field(conn, "SELECT CURRENT_ROLE() AS role", "role", value);
test.assert(strcmp(value, "dba") == 0, "Current role should be 'dba' but is: %s", value);
test.expect(strcmp(value, "dba") == 0, "Current role should be 'dba' but is: %s", value);
mysql_close(conn);
test.tprintf("Connect with a user that doesn't have a default role, expect failure");
conn = open_conn_db(test.maxscales->rwsplit_port[0], test.maxscales->IP[0], "my_db", "test2", "test2");
test.assert(mysql_errno(conn) != 0, "Connection should fail");
test.expect(mysql_errno(conn) != 0, "Connection should fail");
mysql_close(conn);
// Cleanup

View File

@ -68,7 +68,7 @@ void restore_servers(TestConnections& test, bool events_added)
"maxadmin call command mariadbmon switchover MySQL-Monitor server1 server4", true, &dummy);
test.maxscales->wait_for_monitor();
int master_id = get_master_server_id(test);
test.assert(master_id == 1, "Switchover failed to set server1 as master.");
test.expect(master_id == 1, "Switchover failed to set server1 as master.");
}
else
{
@ -112,7 +112,7 @@ int main(int argc, char *argv[])
get_output(test);
int master_id = get_master_server_id(test);
test.assert(master_id == 4, "Server 4 should be master, but master is server %d.", master_id);
test.expect(master_id == 4, "Server 4 should be master, but master is server %d.", master_id);
if (test.global_result != 0)
{
@ -150,7 +150,7 @@ int main(int argc, char *argv[])
test.repl->connect();
int real_id = test.repl->get_server_id(3);
test.assert(master_id == real_id, "@@server_id is different: %d != %d", master_id, real_id);
test.expect(master_id == real_id, "@@server_id is different: %d != %d", master_id, real_id);
print_gtids(test);
test.maxscales->close_maxscale_connections(0);

View File

@ -18,7 +18,7 @@ const StringSet down = {DOWN};
void check_status(TestConnections& test, const char* server, const StringSet& expected, const char* message)
{
StringSet state = test.get_server_status(server);
test.assert(state == expected, "%s: %s", message, dump_status(state, expected).c_str());
test.expect(state == expected, "%s: %s", message, dump_status(state, expected).c_str());
}
static bool is_running = true;

View File

@ -53,7 +53,7 @@ int main(int argc, char** argv)
test.maxscales->wait_for_monitor();
get_output(test);
int master_id = get_master_server_id(test);
test.assert(master_id == -1, "Master was promoted even when no slave was eligible.");
test.expect(master_id == -1, "Master was promoted even when no slave was eligible.");
test.repl->unblock_node(0);

View File

@ -462,17 +462,17 @@ bool check_server_status(TestConnections& test, int id)
else
{
cout << result;
test.assert(false, "Merely 'Running' node did not error in expected way.");
test.expect(false, "Merely 'Running' node did not error in expected way.");
}
}
else
{
test.assert(false, "Could not execute \"SHOW SLAVE STATUS\"");
test.expect(false, "Could not execute \"SHOW SLAVE STATUS\"");
}
}
else
{
test.assert(false, "Unexpected server state for %s.", server.c_str());
test.expect(false, "Unexpected server state for %s.", server.c_str());
}
cout << endl;
@ -497,7 +497,7 @@ void check_server_statuses(TestConnections& test)
}
else if (masters != 1)
{
test.assert(!true, "Unexpected number of masters: %d", masters);
test.expect(!true, "Unexpected number of masters: %d", masters);
}
}
@ -552,7 +552,7 @@ void run(TestConnections& test)
}
else
{
test.assert(false, "Unexpected master id: %d");
test.expect(false, "Unexpected master id: %d");
}
}

View File

@ -47,7 +47,7 @@ int main(int argc, char** argv)
// Mess with the slaves to fix situation such that only one slave can be rejoined. Stop maxscale.
if (test.stop_maxscale(0))
{
test.assert(false, "Could not stop MaxScale.");
test.expect(false, "Could not stop MaxScale.");
return test.global_result;
}
@ -66,7 +66,7 @@ int main(int argc, char** argv)
mysql_query(nodes[i], RESET_SLAVE) != 0 ||
mysql_query(nodes[i], READ_ONLY_OFF) != 0)
{
test.assert(false, "Could not stop slave connections and/or disable read_only for node %d.", i);
test.expect(false, "Could not stop slave connections and/or disable read_only for node %d.", i);
return test.global_result;
}
}
@ -86,7 +86,7 @@ int main(int argc, char** argv)
}
print_gtids(test);
bool gtids_ok = (gtid_begin == gtid_node2 && gtid_node2 < gtid_node3);
test.assert(gtids_ok, "Gtid:s have not advanced correctly.");
test.expect(gtids_ok, "Gtid:s have not advanced correctly.");
if (!gtids_ok)
{
return test.global_result;
@ -95,7 +95,7 @@ int main(int argc, char** argv)
test.tprintf(LINE);
if (test.start_maxscale(0))
{
test.assert(false, "Could not start MaxScale.");
test.expect(false, "Could not start MaxScale.");
return test.global_result;
}
test.maxscales->wait_for_monitor();
@ -105,8 +105,8 @@ int main(int argc, char** argv)
StringSet node3_states = test.get_server_status("server4");
bool states_n2_ok = (node2_states.find("Slave") != node2_states.end());
bool states_n3_ok = (node3_states.find("Slave") == node3_states.end());
test.assert(states_n2_ok, "Node 2 has not rejoined when it should have.");
test.assert(states_n3_ok, "Node 3 rejoined when it shouldn't have.");
test.expect(states_n2_ok, "Node 2 has not rejoined when it should have.");
test.expect(states_n3_ok, "Node 3 rejoined when it shouldn't have.");
if (!states_n2_ok || !states_n3_ok)
{
return test.global_result;
@ -122,11 +122,11 @@ int main(int argc, char** argv)
test.maxscales->wait_for_monitor();
get_output(test);
int master_id = get_master_server_id(test);
test.assert(master_id == 4, "Server 4 should be the cluster master.");
test.expect(master_id == 4, "Server 4 should be the cluster master.");
StringSet node0_states = test.get_server_status("server1");
bool states_n0_ok = (node0_states.find("Slave") != node0_states.end() &&
node0_states.find("Relay Master") == node0_states.end());
test.assert(states_n0_ok, "Server 1 is not a slave when it should be.");
test.expect(states_n0_ok, "Server 1 is not a slave when it should be.");
if (states_n0_ok)
{
int ec;
@ -134,7 +134,7 @@ int main(int argc, char** argv)
"maxadmin call command mysqlmon switchover MySQL-Monitor server1 server4" , true, &ec);
test.maxscales->wait_for_monitor();
master_id = get_master_server_id(test);
test.assert(master_id == 1, "Server 1 should be the cluster master.");
test.expect(master_id == 1, "Server 1 should be the cluster master.");
get_output(test);
}

View File

@ -92,7 +92,7 @@ int main(int argc, char** argv)
get_output(test);
int master_id_new = get_master_server_id(test);
cout << "Master server id is " << master_id_new << endl;
test.assert(master_id_new > 0 && master_id_new != master_id_old,
test.expect(master_id_new > 0 && master_id_new != master_id_old,
"Failover did not promote a new master.");
if (test.global_result != 0)
{
@ -102,7 +102,7 @@ int main(int argc, char** argv)
// Stop maxscale to prevent an unintended rejoin.
if (test.stop_maxscale(0))
{
test.assert(false, "Could not stop MaxScale.");
test.expect(false, "Could not stop MaxScale.");
return test.global_result;
}
// Restart old master. Then add some events to it.
@ -115,7 +115,7 @@ int main(int argc, char** argv)
// Restart maxscale. Should not rejoin old master.
if (test.start_maxscale(0))
{
test.assert(false, "Could not start MaxScale.");
test.expect(false, "Could not start MaxScale.");
return test.global_result;
}
test.maxscales->wait_for_monitor();

View File

@ -47,7 +47,7 @@ int main(int argc, char** argv)
test.tprintf(LINE);
test.tprintf(PRINT_ID, master_id);
const bool failover_ok = (master_id > 0 && master_id != old_master_id);
test.assert(failover_ok, "Master did not change or no master detected.");
test.expect(failover_ok, "Master did not change or no master detected.");
string gtid_final;
if (failover_ok)
{
@ -76,7 +76,7 @@ int main(int argc, char** argv)
test.tprintf(LINE);
print_gtids(test);
test.tprintf(LINE);
test.assert(gtid_final == gtid_old_master, "Old master did not successfully rejoin the cluster.");
test.expect(gtid_final == gtid_old_master, "Old master did not successfully rejoin the cluster.");
// Switch master back to server1 so last check is faster
int ec;
test.maxscales->ssh_node_output(0, "maxadmin call command mysqlmon switchover "
@ -84,7 +84,7 @@ int main(int argc, char** argv)
test.maxscales->wait_for_monitor(); // Wait for monitor to update status
get_output(test);
master_id = get_master_server_id(test);
test.assert(master_id == old_master_id, "Switchover back to server1 failed.");
test.expect(master_id == old_master_id, "Switchover back to server1 failed.");
}
else
{

View File

@ -51,7 +51,7 @@ int main(int argc, char** argv)
int master_id = get_master_server_id(test);
cout << "Master server id is " << master_id << endl;
const bool failover_ok = (master_id > 0 && master_id != old_master_id);
test.assert(failover_ok, "Master did not change or no master detected.");
test.expect(failover_ok, "Master did not change or no master detected.");
string gtid_final;
if (failover_ok)
{
@ -82,7 +82,7 @@ int main(int argc, char** argv)
cout << LINE << "\n";
print_gtids(test);
cout << LINE << "\n";
test.assert(gtid_final == gtid_old_master, "Old master did not successfully rejoin the cluster (%s != %s).", gtid_final.c_str(), gtid_old_master.c_str());
test.expect(gtid_final == gtid_old_master, "Old master did not successfully rejoin the cluster (%s != %s).", gtid_final.c_str(), gtid_old_master.c_str());
// Switch master back to server1 so last check is faster
int ec;
test.maxscales->ssh_node_output(0, "maxadmin call command mysqlmon switchover "
@ -90,7 +90,7 @@ int main(int argc, char** argv)
test.maxscales->wait_for_monitor(); // Wait for monitor to update status
get_output(test);
master_id = get_master_server_id(test);
test.assert(master_id == old_master_id, "Switchover back to server1 failed.");
test.expect(master_id == old_master_id, "Switchover back to server1 failed.");
}
else
{

View File

@ -62,7 +62,7 @@ int main(int argc, char** argv)
mysql_query(nodes[i], RESET_SLAVE) != 0 ||
mysql_query(nodes[i], READ_ONLY_OFF) != 0)
{
test.assert(false, "Could not stop slave connections and/or disable read_only for node %d.", i);
test.expect(false, "Could not stop slave connections and/or disable read_only for node %d.", i);
return test.global_result;
}
}
@ -82,7 +82,7 @@ int main(int argc, char** argv)
}
print_gtids(test);
bool gtids_ok = (gtid_begin == gtid_node2 && gtid_node2 < gtid_node3);
test.assert(gtids_ok, "Gtid:s have not advanced correctly.");
test.expect(gtids_ok, "Gtid:s have not advanced correctly.");
if (!gtids_ok)
{
return test.global_result;
@ -101,8 +101,8 @@ int main(int argc, char** argv)
StringSet node3_states = test.get_server_status("server4");
bool states_n2_ok = (node2_states.find("Slave") != node2_states.end());
bool states_n3_ok = (node3_states.find("Slave") == node3_states.end());
test.assert(states_n2_ok, "Node 2 has not rejoined when it should have.");
test.assert(states_n3_ok, "Node 3 rejoined when it shouldn't have.");
test.expect(states_n2_ok, "Node 2 has not rejoined when it should have.");
test.expect(states_n3_ok, "Node 3 rejoined when it shouldn't have.");
if (!states_n2_ok || !states_n3_ok)
{
return test.global_result;
@ -122,11 +122,11 @@ int main(int argc, char** argv)
test.maxscales->wait_for_monitor();
get_output(test);
int master_id = get_master_server_id(test);
test.assert(master_id == 4, "Server 4 should be the cluster master.");
test.expect(master_id == 4, "Server 4 should be the cluster master.");
StringSet node0_states = test.get_server_status("server1");
bool states_n0_ok = (node0_states.find("Slave") != node0_states.end() &&
node0_states.find("Relay Master") == node0_states.end());
test.assert(states_n0_ok, "Server 1 is not a slave when it should be.");
test.expect(states_n0_ok, "Server 1 is not a slave when it should be.");
if (states_n0_ok)
{
int ec;
@ -134,7 +134,7 @@ int main(int argc, char** argv)
"maxadmin call command mysqlmon switchover MySQL-Monitor server1 server4" , true, &ec);
test.maxscales->wait_for_monitor();
master_id = get_master_server_id(test);
test.assert(master_id == 1, "Server 1 should be the cluster master.");
test.expect(master_id == 1, "Server 1 should be the cluster master.");
get_output(test);
}

View File

@ -96,7 +96,7 @@ void expect(TestConnections& test, const char* zServer, const StringSet& expecte
if (found != expected)
{
test.assert(false, "Found states are not the same as the expected ones.");
test.expect(false, "Found states are not the same as the expected ones.");
++test.global_result;
}

View File

@ -450,18 +450,18 @@ bool check_server_status(TestConnections& test, int id)
if (find_field(pConn, "SHOW SLAVE STATUS", "Last_IO_Error", result) == 0)
{
cout << result << endl;
test.assert(false, "Server is neither slave, nor master.");
test.expect(false, "Server is neither slave, nor master.");
}
else
{
cout << "?" << endl;
test.assert(false, "Could not execute \"SHOW SLAVE STATUS\"");
test.expect(false, "Could not execute \"SHOW SLAVE STATUS\"");
}
}
else
{
cout << "?" << endl;
test.assert(false, "Unexpected server state for %s.", server.c_str());
test.expect(false, "Unexpected server state for %s.", server.c_str());
}
return is_master;
@ -476,7 +476,7 @@ void check_server_statuses(TestConnections& test)
masters += check_server_status(test, 3);
masters += check_server_status(test, 4);
test.assert(masters == 1, "Unpexpected number of masters: %d", masters);
test.expect(masters == 1, "Unpexpected number of masters: %d", masters);
}
int get_next_master_id(TestConnections& test, int current_id)
@ -600,18 +600,18 @@ void run(TestConnections& test)
if (master_id < 0)
{
test.assert(false, "No master available after switchover.");
test.expect(false, "No master available after switchover.");
}
else if (master_id != current_master_id)
{
test.assert(false,
test.expect(false,
"Master should have been server%d, but it was server%d.",
current_master_id, master_id);
}
}
else
{
test.assert(false,
test.expect(false,
"Could not find any slave to switch to.");
}
}

View File

@ -25,7 +25,7 @@ int main(int argc, char** argv)
for (auto a : statements)
{
test.assert(execute_query_check_one(test.maxscales->conn_rwsplit[0], a.first, a.second) == 0,
test.expect(execute_query_check_one(test.maxscales->conn_rwsplit[0], a.first, a.second) == 0,
"Expected '%s' for query: %s", a.second, a.first);
}
@ -39,7 +39,7 @@ int main(int argc, char** argv)
for (auto a : oracle_statements)
{
test.assert(execute_query_check_one(test.maxscales->conn_rwsplit[0], a.first, a.second) == 0,
test.expect(execute_query_check_one(test.maxscales->conn_rwsplit[0], a.first, a.second) == 0,
"Expected '%s' for query: %s", a.second, a.first);
}

View File

@ -401,7 +401,7 @@ void TestConnections::add_result(bool result, const char *format, ...)
}
}
void TestConnections::assert(bool result, const char *format, ...)
void TestConnections::expect(bool result, const char *format, ...)
{
if (!result)
{
@ -811,7 +811,7 @@ int TestConnections::copy_maxscale_logs(double timestamp)
const char* command = "ls /tmp/core* && exit 42";
int rc = maxscales->ssh_node_f(i, true, command);
assert(rc != 42, "Test should not generate core files");
expect(rc != 42, "Test should not generate core files");
}
return 0;
}

View File

@ -252,7 +252,7 @@ public:
void add_result(bool result, const char *format, ...);
/** Same as add_result() but inverted */
void assert(bool result, const char *format, ...);
void expect(bool result, const char *format, ...);
/**
* @brief ReadEnv Reads all Maxscale and Master/Slave and Galera setups info from environmental variables