From: Razvan Becheriu Date: Thu, 12 Sep 2019 12:42:23 +0000 (+0300) Subject: [#886, !508] clean up X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8490599424e14a5abc63611278d0e5ad486c1d37;p=thirdparty%2Fkea.git [#886, !508] clean up --- diff --git a/src/lib/dhcpsrv/tests/thread_resource_mgr_unittest.cc b/src/lib/dhcpsrv/tests/thread_resource_mgr_unittest.cc index 7c1227cd1e..42a67798d9 100644 --- a/src/lib/dhcpsrv/tests/thread_resource_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/thread_resource_mgr_unittest.cc @@ -37,8 +37,7 @@ public: Resource::count_++; // increase the total number of instances ever created Resource::created_count_++; - // check that this instance in new and should not be found in the - // verification set + // check that this instance is not found in the verification set EXPECT_TRUE(Resource::set_.find(&data_) == Resource::set_.end()); // add this instance to the verification set Resource::set_.emplace(&data_); @@ -107,7 +106,7 @@ private: /// @brief mutex used to keep the internal state consistent static std::mutex mutex_; - /// @brief set to fold + /// @brief set to hold the distinct identification data of each instance static std::set set_; }; @@ -151,12 +150,16 @@ public: wait_cv_.notify_all(); } - /// @brief reset resource manager for the template class and perform sanity - /// checks + /// @brief reset resource manager for the specific class type and perform + /// sanity checks, then reset the wait flag so threads wait for the main + /// thread signal to exit template void reset() { + // reset the resource manager get() = make_shared>>(); + // perform sanity checks sanityCheck(); + // reset the wait flag wait_ = true; } @@ -177,17 +180,10 @@ public: ASSERT_EQ(Resource::destroyedCount(), expected_destroyed); } - /// @brief sanity check that the number of created instances is equal to the - /// number of destroyed instances - template - void sanityCheck() { - ASSERT_EQ(Resource::createdCount(), Resource::destroyedCount()); - } - /// @brief get the instance of the resource manager responsible for a - /// specific class + /// specific class type /// - /// @return the resource manager responsible for a specific class + /// @return the resource manager responsible for a specific class type template shared_ptr>> &get() { static shared_ptr>> container; @@ -229,6 +225,15 @@ public: } private: + /// @brief sanity check that the number of created instances is equal to the + /// number of destroyed instances + template + void sanityCheck() { + // the number of created instances should match the number of destroyed + // instances + ASSERT_EQ(Resource::createdCount(), Resource::destroyedCount()); + } + /// @brief mutex used to keep the internal state consistent /// related to the control of the main thread over the working threads exit std::mutex wait_mutex_;