diff --git a/tests/db_access/settings.hpp b/tests/db_access/settings.hpp index fa5ffa6..c6e2b43 100644 --- a/tests/db_access/settings.hpp +++ b/tests/db_access/settings.hpp @@ -24,6 +24,7 @@ struct Setting std::string database{"test_superior_sqlpp"}; std::uint16_t port{0}; std::string containerId{""}; + bool verbose{false}; }; inline Setting& getSettingsRef() @@ -35,6 +36,10 @@ inline Setting& getSettingsRef() inline void systemExecute(std::string command) { + if (getSettingsRef().verbose) + { + std::cout << "Executing: " << command << std::endl; + } auto returnCode = std::system(command.c_str()); if (returnCode != 0) { @@ -45,32 +50,36 @@ inline void systemExecute(std::string command) inline void startMySql() { - systemExecute("docker exec " + getSettingsRef().containerId + " supervisorctl start mysqld 1>/dev/null"); + systemExecute("docker exec " + getSettingsRef().containerId + " supervisorctl start mysqld"); } inline void stopMySql() { - systemExecute("docker exec " + getSettingsRef().containerId + " supervisorctl stop mysqld 1>/dev/null"); + systemExecute("docker exec " + getSettingsRef().containerId + " supervisorctl stop mysqld"); } inline void restartMySql() { - systemExecute("docker exec " + getSettingsRef().containerId + " supervisorctl restart mysqld 1>/dev/null"); + systemExecute("docker exec " + getSettingsRef().containerId + " supervisorctl restart mysqld"); } inline void waitForMySql() { + auto& s = getSettingsRef(); while (true) { try { - auto& s = getSettingsRef(); std::this_thread::sleep_for(std::chrono::milliseconds{100}); SuperiorMySqlpp::Connection connection{"", s.user, s.password, s.host, s.port}; } catch (std::exception& e) { - std::this_thread::sleep_for(std::chrono::milliseconds{50}); + if (s.verbose) + { + std::cout << "Connecting to " << s.user << "@" << s.host << ":" << s.port << " failed: " << e.what() << std::endl; + } + std::this_thread::sleep_for(std::chrono::seconds{10}); continue; } diff --git a/tests/main.cpp b/tests/main.cpp index f11c1b6..2f012c1 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -35,7 +35,7 @@ class Singleton void printUsage() { - std::cerr << "Usage: ./tester [bandit-options...]" << std::endl; + std::cerr << "Usage: [VERBOSE=1] ./tester [bandit-options...]" << std::endl; } int main(int argc, char* argv[]) @@ -48,6 +48,13 @@ int main(int argc, char* argv[]) } auto& s = getSettingsRef(); + s.verbose = []{ + if (char* varText = std::getenv("VERBOSE")) + { + return std::stoi(varText) != 0; + } + return false; + }; s.host = argv[1]; try { @@ -64,7 +71,10 @@ int main(int argc, char* argv[]) Singleton::getInstance(); -// SuperiorMySqlpp::DefaultLogger::getModifiableInstance().setLoggerPtr(std::make_shared()); + if (s.verbose) + { + SuperiorMySqlpp::DefaultLogger::getModifiableInstance().setLoggerPtr(std::make_shared()); + } std::cout << "Waiting for MySQL to become ready..." << std::endl; waitForMySql();