Skip to content

Commit a48080a

Browse files
committed
test/common: add death test for double !recursive lock
Signed-off-by: Patrick Donnelly <[email protected]>
1 parent 84ebb30 commit a48080a

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/test/common/test_mutex_debug.cc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,13 @@ TEST(MutexDebug, Lock) {
5757
test_lock<ceph::mutex_debug>();
5858
}
5959

60-
TEST(MutexDebug, NotRecursive) {
60+
TEST(MutexDebugDeathTest, NotRecursive) {
6161
ceph::mutex_debug m("foo");
62-
auto ttl = &test_try_lock<mutex_debug>;
63-
64-
ASSERT_NO_THROW(m.lock());
65-
ASSERT_TRUE(m.is_locked());
66-
ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get());
67-
62+
// avoid assert during test cleanup where the mutex is locked and cannot be
63+
// pthread_mutex_destroy'd
64+
std::unique_lock locker{m};
6865
ASSERT_TRUE(m.is_locked());
69-
ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get());
70-
71-
ASSERT_NO_THROW(m.unlock());
72-
ASSERT_FALSE(m.is_locked());
73-
ASSERT_TRUE(std::async(std::launch::async, ttl, &m).get());
66+
ASSERT_DEATH(m.lock(), "FAILED ceph_assert(recursive || !is_locked_by_me())");
7467
}
7568

7669
TEST(MutexRecursiveDebug, Lock) {

0 commit comments

Comments
 (0)