bool DatabaseConnection::retry_ = false;
IOServicePtr DatabaseConnection::io_service_ = IOServicePtr();
+bool DatabaseConnection::test_mode_ = false;
+
} // namespace db
} // namespace isc
return (unusable_);
}
+ /// @brief Test mode flag (default false).
+ static bool test_mode_;
+
+ /// @brief RAII device to set the test mode.
+ class EnterTest {
+ public:
+
+ /// @brief Constructor.
+ /// Set the test mode to true.
+ EnterTest() {
+ DatabaseConnection::test_mode_ = true;
+ }
+
+ /// @brief Destructor.
+ /// Reset the test mode to false.
+ ~EnterTest() {
+ DatabaseConnection::test_mode_ = false;
+ }
+ };
+
protected:
/// @brief Sets the unusable flag to true.
ASSERT_TRUE(elements);
ASSERT_EQ(0, elements->size());
}
+
+// Check that the test mode works as expected.
+TEST(DatabaseConnection, testMode) {
+ ASSERT_FALSE(DatabaseConnection::test_mode_);
+ {
+ DatabaseConnection::EnterTest et;
+ EXPECT_TRUE(DatabaseConnection::test_mode_);
+ }
+ EXPECT_FALSE(DatabaseConnection::test_mode_);
+}
destroyMySQLSchema();
createMySQLSchema();
+ // Enter test mode to avoid ensureSchemaVersion to invole kea-admin.
+ DatabaseConnection::EnterTest et;
+
// Check that host manager opens the database correctly and tidy up. If it
// fails, print the error message.
try {
destroyMySQLSchema();
createMySQLSchema();
+ // Enter test mode to avoid ensureSchemaVersion to invole kea-admin.
+ DatabaseConnection::EnterTest et;
+
// Check that host manager opens the database correctly and tidy up. If it
// fails, print the error message.
try {
// Schema needs to be created for the test to work.
createMySQLSchema(true);
+ // Enter test mode to avoid ensureSchemaVersion to invole kea-admin.
+ DatabaseConnection::EnterTest et;
+
// Check that lease manager opens the database correctly and tidy up. If it
// fails, print the error message.
try {
destroyPgSQLSchema();
createPgSQLSchema();
+ // Enter test mode to avoid ensureSchemaVersion to invole kea-admin.
+ DatabaseConnection::EnterTest et;
+
// Check that host manager opens the database correctly and tidy up. If it
// fails, print the error message.
try {
destroyPgSQLSchema();
createPgSQLSchema();
+ // Enter test mode to avoid ensureSchemaVersion to invole kea-admin.
+ DatabaseConnection::EnterTest et;
+
// Check that host manager opens the database correctly and tidy up. If it
// fails, print the error message.
try {
// Schema needs to be created for the test to work.
createPgSQLSchema();
+ // Enter test mode to avoid ensureSchemaVersion to invole kea-admin.
+ DatabaseConnection::EnterTest et;
+
// Check that lease manager opens the database correctly and tidy up. If it
// fails, print the error message.
try {
} catch (DbOpenErrorWithRetry const& exception) {
throw;
} catch (exception const& exception) {
+ // Disable the recovery mechanism in test mode.
+ if (DatabaseConnection::test_mode_) {
+ throw;
+ }
// This failure may occur for a variety of reasons. We are looking at
// initializing schema as the only potential mitigation. We could narrow
// down on the error that would suggest an uninitialized schema
} catch (DbOpenErrorWithRetry const& exception) {
throw;
} catch (exception const& exception) {
+ // Disable the recovery mechanism in test mode.
+ if (DatabaseConnection::test_mode_) {
+ throw;
+ }
// This failure may occur for a variety of reasons. We are looking at
// initializing schema as the only potential mitigation. We could narrow
// down on the error that would suggest an uninitialized schema