Use execute_query instead of try_query when failure expected

try_query will log an error unnecessarily.
This commit is contained in:
Johan Wikman
2017-12-19 14:50:45 +02:00
parent 628203213e
commit 34bb02062d

View File

@ -77,24 +77,16 @@ void stop_node(Mariadb_nodes& nodes, int node)
} }
} }
void fail(void (*f)(TestConnections&), TestConnections& test) void fail_query(TestConnections& test)
{ {
bool failed = false; int rv = execute_query(test.maxscales->conn_rwsplit[0], "BEGIN");
int global_result = test.global_result;
try if (rv == 0)
{ {
f(test); const char MESSAGE[] = "A query that was expected to fail, did not fail.";
}
catch (const std::exception& x)
{
test.global_result = global_result;
failed = true;
}
if (!failed) test.add_result(false, "%s", MESSAGE);
{ throw std::runtime_error(MESSAGE);
throw std::runtime_error("Function did not fail as expected.");
} }
} }
@ -151,8 +143,8 @@ void run(TestConnections& test)
list_servers(test); list_servers(test);
cout << "\nShould fail as master is no longer available, but trying to insert data... " << endl; cout << "\nShould fail as master is no longer available, but trying to execute a query... " << endl;
x::fail(insert_data, test); x::fail_query(test);
cout << "Failed as expected." << endl; cout << "Failed as expected." << endl;
list_servers(test); list_servers(test);
@ -163,8 +155,8 @@ void run(TestConnections& test)
list_servers(test); list_servers(test);
cout << "\nShould still fail as there is not transparent master failover, " cout << "\nShould still fail as there is not transparent master failover, "
<< "but trying to insert data... " << endl; << "but trying to execute a query... " << endl;
x::fail(insert_data, test); x::fail_query(test);
cout << "Failed as expected." << endl; cout << "Failed as expected." << endl;
cout << "\nClosing connection to MaxScale." << endl; cout << "\nClosing connection to MaxScale." << endl;