mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 13:37:55 +00:00
[2205] avoid referencing post-destructor member variables.
by a bit ugly hack: we specialize some part of the destructor and make a local copy of these variables so the tests can inspect them later.
This commit is contained in:
@@ -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) {
|
||||
{
|
||||
|
@@ -23,8 +23,11 @@ namespace datasrc_clientmgr_internal {
|
||||
// Define static DataSrcClientsBuilder member variables.
|
||||
bool FakeDataSrcClientsBuilder::started = false;
|
||||
std::list<Command>* FakeDataSrcClientsBuilder::command_queue = NULL;
|
||||
std::list<Command> 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++
|
||||
|
@@ -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>* command_queue;
|
||||
static TestCondVar* cond;
|
||||
static TestMutex* queue_mutex;
|
||||
static std::list<Command> 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
|
||||
|
||||
|
Reference in New Issue
Block a user