From: JINMEI Tatuya Date: Sat, 20 Oct 2012 05:33:01 +0000 (-0700) Subject: [2211] test duplicate mgr holder acquisition instead using auth locker X-Git-Tag: trac2402_base~3^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a9af8c8a7a7d2448c86949fca578ec942e5413dd;p=thirdparty%2Fkea.git [2211] test duplicate mgr holder acquisition instead using auth locker the latter will soon be deprecated. --- diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc index 0781d578b5..90df8dcefb 100644 --- a/src/bin/auth/tests/auth_srv_unittest.cc +++ b/src/bin/auth/tests/auth_srv_unittest.cc @@ -1787,17 +1787,4 @@ TEST_F(AuthSrvTest, DDNSForwardCreateDestroy) { Opcode::UPDATE().getCode(), QR_FLAG, 0, 0, 0, 0); } -// We just test the mutex can be locked (exactly once). -TEST_F(AuthSrvTest, mutex) { - isc::util::thread::Mutex::Locker l1(server.getDataSrcClientListMutex()); - // TODO: Once we have non-debug build, this one will not work, since - // we currently use the fact that we can't lock twice from the same - // thread. In the non-debug mode, this would deadlock. - // Skip then. - EXPECT_THROW({ - isc::util::thread::Mutex::Locker l2( - server.getDataSrcClientListMutex()); - }, isc::InvalidOperation); -} - } diff --git a/src/bin/auth/tests/datasrc_clients_mgr_unittest.cc b/src/bin/auth/tests/datasrc_clients_mgr_unittest.cc index 7dbee06d4a..3fefda03f8 100644 --- a/src/bin/auth/tests/datasrc_clients_mgr_unittest.cc +++ b/src/bin/auth/tests/datasrc_clients_mgr_unittest.cc @@ -189,8 +189,12 @@ TEST(DataSrcClientsMgrTest, holder) { EXPECT_TRUE(holder.findClientList(RRClass::IN())); EXPECT_FALSE(holder.findClientList(RRClass::CH())); } -} + // Duplicate lock acquisition is prohibited (only test mgr can detect + // this reliably, so this test may not be that useful) + TestDataSrcClientsMgr::Holder holder1(mgr); + EXPECT_THROW(TestDataSrcClientsMgr::Holder holder2(mgr), isc::Unexpected); +} TEST(DataSrcClientsMgrTest, realThread) { // Using the non-test definition with a real thread. Just checking diff --git a/src/bin/auth/tests/test_datasrc_clients_mgr.h b/src/bin/auth/tests/test_datasrc_clients_mgr.h index 7406e29eca..846aa70e55 100644 --- a/src/bin/auth/tests/test_datasrc_clients_mgr.h +++ b/src/bin/auth/tests/test_datasrc_clients_mgr.h @@ -51,6 +51,11 @@ public: class Locker { public: Locker(TestMutex& mutex) : mutex_(mutex) { + if (mutex.lock_count != mutex.unlock_count) { + isc_throw(Unexpected, + "attempt of duplicate lock acquisition"); + } + ++mutex.lock_count; if (mutex.lock_count > 100) { // 100 is an arbitrary choice isc_throw(Unexpected,