Browse Source

[4544] Prevent unexpected closing of connection to the host database.

Marcin Siodelski 8 years ago
parent
commit
b7b75e4b00
2 changed files with 17 additions and 1 deletions
  1. 2 1
      src/lib/dhcpsrv/cfg_db_access.cc
  2. 15 0
      src/lib/dhcpsrv/tests/cfg_db_access_unittest.cc

+ 2 - 1
src/lib/dhcpsrv/cfg_db_access.cc

@@ -7,6 +7,7 @@
 #include <config.h>
 #include <dhcpsrv/cfg_db_access.h>
 #include <dhcpsrv/host_data_source_factory.h>
+#include <dhcpsrv/host_mgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <sstream>
 
@@ -39,7 +40,7 @@ CfgDbAccess::createManagers() const {
     // Recreate host data source.
     HostDataSourceFactory::destroy();
     if (!host_db_access_.empty()) {
-        HostDataSourceFactory::create(getHostDbAccessString());
+        HostMgr::create(getHostDbAccessString());
     }
 }
 

+ 15 - 0
src/lib/dhcpsrv/tests/cfg_db_access_unittest.cc

@@ -7,6 +7,7 @@
 #include <config.h>
 #include <dhcpsrv/cfg_db_access.h>
 #include <dhcpsrv/host_data_source_factory.h>
+#include <dhcpsrv/host_mgr.h>
 #include <dhcpsrv/lease_mgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/testutils/mysql_schema.h>
@@ -108,6 +109,20 @@ TEST_F(CfgMySQLDbAccessTest, createManagers) {
     ASSERT_NO_THROW({
         HostDataSourcePtr& host_data_source =
             HostDataSourceFactory::getHostDataSourcePtr();
+        ASSERT_TRUE(host_data_source);
+        EXPECT_EQ("mysql", host_data_source->getType());
+    });
+
+    // Because of the lazy initialization of the HostMgr instance, it is
+    // possible that the first call to the instance() function tosses
+    // existing connection to the database created by the call to
+    // createManagers(). Let's make sure that this doesn't happen.
+    ASSERT_NO_THROW(HostMgr::instance());
+
+    ASSERT_NO_THROW({
+        HostDataSourcePtr& host_data_source =
+            HostDataSourceFactory::getHostDataSourcePtr();
+        ASSERT_TRUE(host_data_source);
         EXPECT_EQ("mysql", host_data_source->getType());
     });
 }