From 2b71741cfee235cdbfb69c101bb6ac06a5da436c Mon Sep 17 00:00:00 2001 From: Judah Schvimer Date: Sun, 18 Nov 2018 15:50:40 -0500 Subject: SERVER-37989 introduce a new ReplicationStateTransitionLock resource --- src/mongo/db/concurrency/lock_state_test.cpp | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/mongo/db/concurrency/lock_state_test.cpp') diff --git a/src/mongo/db/concurrency/lock_state_test.cpp b/src/mongo/db/concurrency/lock_state_test.cpp index e2055f11724..a0094d3d485 100644 --- a/src/mongo/db/concurrency/lock_state_test.cpp +++ b/src/mongo/db/concurrency/lock_state_test.cpp @@ -1,4 +1,3 @@ - /** * Copyright (C) 2018-present MongoDB, Inc. * @@ -161,6 +160,43 @@ TEST(LockerImpl, saveAndRestoreGlobal) { ASSERT(locker.unlockGlobal()); } +/** + * Test that saveLockerImpl can save and restore the RSTL. + */ +TEST(LockerImpl, saveAndRestoreRSTL) { + Locker::LockSnapshot lockInfo; + + LockerImpl locker; + + const ResourceId resIdDatabase(RESOURCE_DATABASE, "TestDB"_sd); + + // Acquire locks. + ASSERT_EQUALS(LOCK_OK, locker.lock(resourceIdReplicationStateTransitionLock, MODE_IX)); + locker.lockGlobal(MODE_IX); + ASSERT_EQUALS(LOCK_OK, locker.lock(resIdDatabase, MODE_IX)); + + // Save the lock state. + locker.saveLockStateAndUnlock(&lockInfo); + ASSERT(!locker.isLocked()); + ASSERT_EQUALS(MODE_IX, lockInfo.globalMode); + + // Check locks are unlocked. + ASSERT_EQUALS(MODE_NONE, locker.getLockMode(resourceIdReplicationStateTransitionLock)); + ASSERT(!locker.isLocked()); + ASSERT_EQUALS(MODE_NONE, locker.getLockMode(resIdDatabase)); + + // Restore the lock(s) we had. + locker.restoreLockState(lockInfo); + + // Check locks are re-locked. + ASSERT(locker.isLocked()); + ASSERT_EQUALS(MODE_IX, locker.getLockMode(resIdDatabase)); + ASSERT_EQUALS(MODE_IX, locker.getLockMode(resourceIdReplicationStateTransitionLock)); + + ASSERT(locker.unlockGlobal()); + ASSERT(locker.unlock(resourceIdReplicationStateTransitionLock)); +} + /** * Test that we don't unlock when we have the global lock more than once. */ -- cgit v1.2.1