diff --git a/src/bin/auth/datasrc_clients_mgr.h b/src/bin/auth/datasrc_clients_mgr.h index c3bf1d2440..4cfb170e5b 100644 --- a/src/bin/auth/datasrc_clients_mgr.h +++ b/src/bin/auth/datasrc_clients_mgr.h @@ -128,9 +128,17 @@ public: LOG_ERROR(auth_logger, AUTH_DATASRC_CLIENTS_SHUTDOWN_ERROR). arg(ex.what()); } catch (...) {} + + cleanup(); // see below } private: + // This is expected to be called at the end of the destructor. It + // actually does nothing, but provides a customization point for + // specialized class for tests so that the tests can inspect the last + // state of the class. + void cleanup() {} + void sendCommand(datasrc_clientmgr_internal::CommandID command, data::ConstElementPtr arg) { { diff --git a/src/bin/auth/tests/test_datasrc_clients_mgr.cc b/src/bin/auth/tests/test_datasrc_clients_mgr.cc index 7d114aedd1..72979b4844 100644 --- a/src/bin/auth/tests/test_datasrc_clients_mgr.cc +++ b/src/bin/auth/tests/test_datasrc_clients_mgr.cc @@ -23,8 +23,11 @@ namespace datasrc_clientmgr_internal { // Define static DataSrcClientsBuilder member variables. bool FakeDataSrcClientsBuilder::started = false; std::list* FakeDataSrcClientsBuilder::command_queue = NULL; +std::list FakeDataSrcClientsBuilder::command_queue_copy; TestCondVar* FakeDataSrcClientsBuilder::cond = NULL; +TestCondVar FakeDataSrcClientsBuilder::cond_copy; TestMutex* FakeDataSrcClientsBuilder::queue_mutex = NULL; +TestMutex FakeDataSrcClientsBuilder::queue_mutex_copy; bool FakeDataSrcClientsBuilder::thread_waited = false; FakeDataSrcClientsBuilder::ExceptionFromWait FakeDataSrcClientsBuilder::thread_throw_on_wait = @@ -43,9 +46,29 @@ TestDataSrcClientsBuilder::doNoop() { throw 42; } } +} // namespace datasrc_clientmgr_internal + +template<> +void +TestDataSrcClientsMgr::cleanup() { + using namespace datasrc_clientmgr_internal; + // Make copy of some of the manager's member variables and reset the + // corresponding pointers. The currently pointed objects are in the + // manager object, which are going to be invalidated. + + FakeDataSrcClientsBuilder::command_queue_copy = command_queue_; + FakeDataSrcClientsBuilder::command_queue = + &FakeDataSrcClientsBuilder::command_queue_copy; + FakeDataSrcClientsBuilder::queue_mutex_copy = queue_mutex_; + FakeDataSrcClientsBuilder::queue_mutex = + &FakeDataSrcClientsBuilder::queue_mutex_copy; + FakeDataSrcClientsBuilder::cond_copy = cond_; + FakeDataSrcClientsBuilder::cond = + &FakeDataSrcClientsBuilder::cond_copy; } -} -} + +} // namespace auth +} // namespace isc // Local Variables: // mode: c++ diff --git a/src/bin/auth/tests/test_datasrc_clients_mgr.h b/src/bin/auth/tests/test_datasrc_clients_mgr.h index 911e7220e2..0519425859 100644 --- a/src/bin/auth/tests/test_datasrc_clients_mgr.h +++ b/src/bin/auth/tests/test_datasrc_clients_mgr.h @@ -124,9 +124,14 @@ public: static bool started; // These three correspond to the resource shared with the manager. + // xxx_copy will be set in the manager's destructor to record the + // final state of the manager. static std::list* command_queue; static TestCondVar* cond; static TestMutex* queue_mutex; + static std::list command_queue_copy; + static TestCondVar cond_copy; + static TestMutex queue_mutex_copy; // true iff the manager waited on the thread running the builder. static bool thread_waited; @@ -182,6 +187,13 @@ typedef DataSrcClientsMgrBase< datasrc_clientmgr_internal::TestMutex, datasrc_clientmgr_internal::TestCondVar> TestDataSrcClientsMgr; +// A specialization of manager's "cleanup" called at the end of the +// destructor. We use this to record the final values of some of the class +// member variables. +template<> +void +TestDataSrcClientsMgr::cleanup(); + } // namespace auth } // namespace isc