]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2211] test duplicate mgr holder acquisition instead using auth locker
authorJINMEI Tatuya <jinmei@isc.org>
Sat, 20 Oct 2012 05:33:01 +0000 (22:33 -0700)
committerJINMEI Tatuya <jinmei@isc.org>
Sat, 20 Oct 2012 05:33:01 +0000 (22:33 -0700)
the latter will soon be deprecated.

src/bin/auth/tests/auth_srv_unittest.cc
src/bin/auth/tests/datasrc_clients_mgr_unittest.cc
src/bin/auth/tests/test_datasrc_clients_mgr.h

index 0781d578b56c0fa60b2da8187e15c9b9b8c02d47..90df8dcefb9a8fd4846cdc594a2ef13116a70bed 100644 (file)
@@ -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);
-}
-
 }
index 7dbee06d4a7fc76a987ac65182bb96335a09563b..3fefda03f82ac9040d5b319a95ea73749babd70c 100644 (file)
@@ -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
index 7406e29eca8deae2fc564b55c62666a804bcc959..846aa70e552c6430f83aca7dcb8e0a1b428ae3a9 100644 (file)
@@ -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,