summaryrefslogtreecommitdiff
path: root/src/mongo/db/concurrency
diff options
context:
space:
mode:
authorjannaerin <golden.janna@gmail.com>2023-02-01 20:54:39 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-02-08 02:46:14 +0000
commit567bcd0e4822d726aea15f0338c89c49de2a56b5 (patch)
treefa2a6ea1d3cbd4872fba26df3fdb44548544206f /src/mongo/db/concurrency
parentf7afadd90f50662b2b3b3a45595b65b37a59bdc3 (diff)
downloadmongo-567bcd0e4822d726aea15f0338c89c49de2a56b5.tar.gz
SERVER-73112 Expose function to construct NamespaceString in unit tests
Diffstat (limited to 'src/mongo/db/concurrency')
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp47
-rw-r--r--src/mongo/db/concurrency/lock_manager_test.cpp80
-rw-r--r--src/mongo/db/concurrency/lock_state_test.cpp105
-rw-r--r--src/mongo/db/concurrency/lock_stats_test.cpp18
-rw-r--r--src/mongo/db/concurrency/resource_catalog_test.cpp14
5 files changed, 181 insertions, 83 deletions
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index fae4f83cf84..246eb1610e7 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -1227,7 +1227,7 @@ TEST_F(DConcurrencyTestFixture, IsDbLockedForXMode) {
}
TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IS) {
- const NamespaceString ns("db1.coll");
+ const NamespaceString ns = NamespaceString::createNamespaceString_forTest("db1.coll");
auto opCtx = makeOperationContext();
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
@@ -1255,7 +1255,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IS) {
}
TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IX) {
- const NamespaceString ns("db1.coll");
+ const NamespaceString ns = NamespaceString::createNamespaceString_forTest("db1.coll");
auto opCtx = makeOperationContext();
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
@@ -1874,9 +1874,11 @@ TEST_F(DConcurrencyTestFixture, CollectionLockInInterruptedContextThrowsEvenWhen
{
boost::optional<Lock::CollectionLock> collLock;
- ASSERT_THROWS_CODE(collLock.emplace(opCtx, NamespaceString("db.coll"), MODE_IX),
- AssertionException,
- ErrorCodes::Interrupted);
+ ASSERT_THROWS_CODE(
+ collLock.emplace(
+ opCtx, NamespaceString::createNamespaceString_forTest("db.coll"), MODE_IX),
+ AssertionException,
+ ErrorCodes::Interrupted);
}
}
@@ -1886,15 +1888,18 @@ TEST_F(DConcurrencyTestFixture,
auto opCtx = clients[0].second.get();
Lock::DBLock dbLock(opCtx, DatabaseName(boost::none, "db"), MODE_IX);
- Lock::CollectionLock collLock(opCtx, NamespaceString("db.coll"), MODE_IX);
+ Lock::CollectionLock collLock(
+ opCtx, NamespaceString::createNamespaceString_forTest("db.coll"), MODE_IX);
opCtx->markKilled();
{
boost::optional<Lock::CollectionLock> recursiveCollLock;
- ASSERT_THROWS_CODE(recursiveCollLock.emplace(opCtx, NamespaceString("db.coll"), MODE_X),
- AssertionException,
- ErrorCodes::Interrupted);
+ ASSERT_THROWS_CODE(
+ recursiveCollLock.emplace(
+ opCtx, NamespaceString::createNamespaceString_forTest("db.coll"), MODE_X),
+ AssertionException,
+ ErrorCodes::Interrupted);
}
}
@@ -1906,8 +1911,10 @@ TEST_F(DConcurrencyTestFixture, CollectionLockInInterruptedContextRespectsUninte
opCtx->markKilled();
- UninterruptibleLockGuard noInterrupt(opCtx->lockState()); // NOLINT.
- Lock::CollectionLock collLock(opCtx, NamespaceString("db.coll"), MODE_IX); // Does not throw.
+ UninterruptibleLockGuard noInterrupt(opCtx->lockState()); // NOLINT.
+ Lock::CollectionLock collLock(opCtx,
+ NamespaceString::createNamespaceString_forTest("db.coll"),
+ MODE_IX); // Does not throw.
}
TEST_F(DConcurrencyTestFixture, CollectionLockTimeout) {
@@ -1921,15 +1928,21 @@ TEST_F(DConcurrencyTestFixture, CollectionLockTimeout) {
Lock::DBLock DBL1(opctx1, testDb, MODE_IX, Date_t::max());
ASSERT(opctx1->lockState()->isDbLockedForMode(testDb, MODE_IX));
- Lock::CollectionLock CL1(opctx1, NamespaceString("testdb.test"), MODE_X, Date_t::max());
- ASSERT(opctx1->lockState()->isCollectionLockedForMode(NamespaceString("testdb.test"), MODE_X));
+ Lock::CollectionLock CL1(opctx1,
+ NamespaceString::createNamespaceString_forTest("testdb.test"),
+ MODE_X,
+ Date_t::max());
+ ASSERT(opctx1->lockState()->isCollectionLockedForMode(
+ NamespaceString::createNamespaceString_forTest("testdb.test"), MODE_X));
Date_t t1 = Date_t::now();
Lock::DBLock DBL2(opctx2, testDb, MODE_IX, Date_t::max());
ASSERT(opctx2->lockState()->isDbLockedForMode(testDb, MODE_IX));
ASSERT_THROWS_CODE(
- Lock::CollectionLock(
- opctx2, NamespaceString("testdb.test"), MODE_X, Date_t::now() + timeoutMillis),
+ Lock::CollectionLock(opctx2,
+ NamespaceString::createNamespaceString_forTest("testdb.test"),
+ MODE_X,
+ Date_t::now() + timeoutMillis),
AssertionException,
ErrorCodes::LockTimeout);
Date_t t2 = Date_t::now();
@@ -2388,7 +2401,9 @@ TEST_F(DConcurrencyTestFixture, FailPointInLockDoesNotFailUninterruptibleNonInte
LockerImpl locker3(opCtx->getServiceContext());
// Granted MODE_X lock, fail incoming MODE_S and MODE_X.
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
locker1.lockGlobal(opCtx.get(), MODE_IX);
diff --git a/src/mongo/db/concurrency/lock_manager_test.cpp b/src/mongo/db/concurrency/lock_manager_test.cpp
index 8761569c812..c8b53a50f7f 100644
--- a/src/mongo/db/concurrency/lock_manager_test.cpp
+++ b/src/mongo/db/concurrency/lock_manager_test.cpp
@@ -42,7 +42,9 @@ TEST(ResourceId, Semantics) {
ASSERT(resIdDb.getType() == RESOURCE_DATABASE);
ASSERT(resIdDb.getHashId() == 324334234);
- ResourceId resIdColl(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ ResourceId resIdColl(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
ASSERT(resIdColl.getType() == RESOURCE_COLLECTION);
// Comparison functions
@@ -93,7 +95,9 @@ DEATH_TEST_F(ResourceIdTest, CantCreateResourceMutexDirectly, "invariant") {
TEST_F(LockManagerTest, Grant) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(getServiceContext());
TrackingLockGrantNotification notify;
@@ -112,7 +116,9 @@ TEST_F(LockManagerTest, Grant) {
TEST_F(LockManagerTest, GrantMultipleNoConflict) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(getServiceContext());
TrackingLockGrantNotification notify;
@@ -145,7 +151,9 @@ TEST_F(LockManagerTest, GrantMultipleNoConflict) {
TEST_F(LockManagerTest, GrantMultipleFIFOOrder) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
std::unique_ptr<LockerImpl> locker[6];
for (int i = 0; i < 6; i++) {
@@ -178,7 +186,9 @@ TEST_F(LockManagerTest, GrantMultipleFIFOOrder) {
TEST_F(LockManagerTest, GrantRecursive) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(getServiceContext());
LockRequestCombo request(&locker);
@@ -206,7 +216,9 @@ TEST_F(LockManagerTest, GrantRecursive) {
TEST_F(LockManagerTest, GrantRecursiveCompatibleConvertUp) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(getServiceContext());
LockRequestCombo request(&locker);
@@ -234,7 +246,9 @@ TEST_F(LockManagerTest, GrantRecursiveCompatibleConvertUp) {
TEST_F(LockManagerTest, GrantRecursiveNonCompatibleConvertUp) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(getServiceContext());
LockRequestCombo request(&locker);
@@ -262,7 +276,9 @@ TEST_F(LockManagerTest, GrantRecursiveNonCompatibleConvertUp) {
TEST_F(LockManagerTest, GrantRecursiveNonCompatibleConvertDown) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(getServiceContext());
LockRequestCombo request(&locker);
@@ -290,7 +306,9 @@ TEST_F(LockManagerTest, GrantRecursiveNonCompatibleConvertDown) {
TEST_F(LockManagerTest, Conflict) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker1(getServiceContext());
LockerImpl locker2(getServiceContext());
@@ -329,7 +347,9 @@ TEST_F(LockManagerTest, Conflict) {
TEST_F(LockManagerTest, MultipleConflict) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(getServiceContext());
TrackingLockGrantNotification notify;
@@ -362,7 +382,9 @@ TEST_F(LockManagerTest, MultipleConflict) {
TEST_F(LockManagerTest, ConflictCancelWaiting) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker1(getServiceContext());
TrackingLockGrantNotification notify1;
@@ -395,7 +417,9 @@ TEST_F(LockManagerTest, ConflictCancelWaiting) {
TEST_F(LockManagerTest, ConflictCancelMultipleWaiting) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(getServiceContext());
TrackingLockGrantNotification notify;
@@ -428,7 +452,9 @@ TEST_F(LockManagerTest, ConflictCancelMultipleWaiting) {
TEST_F(LockManagerTest, CancelWaitingConversionWeakModes) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker1(getServiceContext());
LockerImpl locker2(getServiceContext());
@@ -463,7 +489,9 @@ TEST_F(LockManagerTest, CancelWaitingConversionWeakModes) {
TEST_F(LockManagerTest, CancelWaitingConversionStrongModes) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker1(getServiceContext());
LockerImpl locker2(getServiceContext());
@@ -498,7 +526,9 @@ TEST_F(LockManagerTest, CancelWaitingConversionStrongModes) {
TEST_F(LockManagerTest, ConflictingConversion) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker1(getServiceContext());
LockerImpl locker2(getServiceContext());
@@ -533,7 +563,9 @@ TEST_F(LockManagerTest, ConflictingConversion) {
TEST_F(LockManagerTest, ConflictingConversionInTheMiddle) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(getServiceContext());
TrackingLockGrantNotification notify;
@@ -565,7 +597,9 @@ TEST_F(LockManagerTest, ConflictingConversionInTheMiddle) {
TEST_F(LockManagerTest, ConvertUpgrade) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker1(getServiceContext());
LockRequestCombo request1(&locker1);
@@ -586,7 +620,9 @@ TEST_F(LockManagerTest, ConvertUpgrade) {
TEST_F(LockManagerTest, Downgrade) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker1(getServiceContext());
LockRequestCombo request1(&locker1);
@@ -614,7 +650,9 @@ static void checkConflict(ServiceContext* serviceContext,
LockMode newMode,
bool hasConflict) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl lockerExisting(serviceContext);
TrackingLockGrantNotification notifyExisting;
@@ -663,7 +701,9 @@ TEST_F(LockManagerTest, ValidateConflictMatrix) {
TEST_F(LockManagerTest, EnqueueAtFront) {
LockManager lockMgr;
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl lockerX(getServiceContext());
LockRequestCombo requestX(&lockerX);
diff --git a/src/mongo/db/concurrency/lock_state_test.cpp b/src/mongo/db/concurrency/lock_state_test.cpp
index 43784795915..d0475730565 100644
--- a/src/mongo/db/concurrency/lock_state_test.cpp
+++ b/src/mongo/db/concurrency/lock_state_test.cpp
@@ -55,7 +55,9 @@ class LockerImplTest : public ServiceContextTest {};
TEST_F(LockerImplTest, LockNoConflict) {
auto opCtx = makeOperationContext();
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(opCtx->getServiceContext());
locker.lockGlobal(opCtx.get(), MODE_IX);
@@ -75,7 +77,9 @@ TEST_F(LockerImplTest, LockNoConflict) {
TEST_F(LockerImplTest, ReLockNoConflict) {
auto opCtx = makeOperationContext();
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(opCtx->getServiceContext());
locker.lockGlobal(opCtx.get(), MODE_IX);
@@ -95,7 +99,9 @@ TEST_F(LockerImplTest, ReLockNoConflict) {
TEST_F(LockerImplTest, ConflictWithTimeout) {
auto opCtx = makeOperationContext();
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker1(opCtx->getServiceContext());
locker1.lockGlobal(opCtx.get(), MODE_IX);
@@ -119,7 +125,9 @@ TEST_F(LockerImplTest, ConflictWithTimeout) {
TEST_F(LockerImplTest, ConflictUpgradeWithTimeout) {
auto opCtx = makeOperationContext();
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker1(opCtx->getServiceContext());
locker1.lockGlobal(opCtx.get(), MODE_IS);
@@ -175,7 +183,9 @@ TEST_F(LockerImplTest, FailPointInLockFailsNonIntentLocksIfTheyCannotBeImmediate
auto newOpCtx = cc().makeOperationContext();
// Granted MODE_X lock, fail incoming MODE_S and MODE_X.
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker1(newOpCtx->getServiceContext());
locker1.lockGlobal(newOpCtx.get(), MODE_IX);
@@ -336,8 +346,9 @@ TEST_F(LockerImplTest, saveAndRestoreDBAndCollection) {
LockerImpl locker(opCtx->getServiceContext());
const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
- const ResourceId resIdCollection(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resIdCollection(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
// Lock some stuff.
locker.lockGlobal(opCtx.get(), MODE_IX);
@@ -367,8 +378,9 @@ TEST_F(LockerImplTest, releaseWriteUnitOfWork) {
LockerImpl locker(opCtx->getServiceContext());
const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
- const ResourceId resIdCollection(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resIdCollection(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
locker.beginWriteUnitOfWork();
// Lock some stuff.
@@ -398,8 +410,9 @@ TEST_F(LockerImplTest, restoreWriteUnitOfWork) {
LockerImpl locker(opCtx->getServiceContext());
const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
- const ResourceId resIdCollection(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resIdCollection(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
locker.beginWriteUnitOfWork();
// Lock some stuff.
@@ -441,10 +454,12 @@ TEST_F(LockerImplTest, releaseAndRestoreWriteUnitOfWorkWithoutUnlock) {
LockerImpl locker(opCtx->getServiceContext());
const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
- const ResourceId resIdCollection(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection"));
- const ResourceId resIdCollection2(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection2"));
+ const ResourceId resIdCollection(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
+ const ResourceId resIdCollection2(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection2"));
locker.beginWriteUnitOfWork();
// Lock some stuff.
@@ -559,8 +574,9 @@ TEST_F(LockerImplTest, releaseAndRestoreReadOnlyWriteUnitOfWork) {
LockerImpl locker(opCtx->getServiceContext());
const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
- const ResourceId resIdCollection(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resIdCollection(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
// Snapshot transactions delay shared locks as well.
locker.setSharedLocksShouldTwoPhaseLock(true);
@@ -627,8 +643,9 @@ TEST_F(LockerImplTest, releaseAndRestoreWriteUnitOfWorkWithRecursiveLocks) {
LockerImpl locker(opCtx->getServiceContext());
const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
- const ResourceId resIdCollection(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resIdCollection(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
locker.beginWriteUnitOfWork();
// Lock some stuff.
@@ -734,10 +751,12 @@ TEST_F(LockerImplTest, SharedLocksShouldTwoPhaseLockIsTrue) {
const ResourceId resId1(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB1"));
const ResourceId resId2(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB2"));
- const ResourceId resId3(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection3"));
- const ResourceId resId4(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection4"));
+ const ResourceId resId3(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection3"));
+ const ResourceId resId4(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection4"));
LockerImpl locker(opCtx->getServiceContext());
locker.setSharedLocksShouldTwoPhaseLock(true);
@@ -792,10 +811,12 @@ TEST_F(LockerImplTest, ModeIXAndXLockParticipatesInTwoPhaseLocking) {
const ResourceId resId1(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB1"));
const ResourceId resId2(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB2"));
- const ResourceId resId3(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection3"));
- const ResourceId resId4(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection4"));
+ const ResourceId resId3(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection3"));
+ const ResourceId resId4(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection4"));
LockerImpl locker(opCtx->getServiceContext());
@@ -1030,8 +1051,9 @@ TEST_F(LockerImplTest, GetLockerInfoShouldReportHeldLocks) {
auto opCtx = makeOperationContext();
const ResourceId dbId(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
- const ResourceId collectionId(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId collectionId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
// Take an exclusive lock on the collection.
LockerImpl locker(opCtx->getServiceContext());
@@ -1057,8 +1079,9 @@ TEST_F(LockerImplTest, GetLockerInfoShouldReportPendingLocks) {
auto opCtx = makeOperationContext();
const ResourceId dbId(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
- const ResourceId collectionId(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId collectionId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
// Take an exclusive lock on the collection.
LockerImpl successfulLocker(opCtx->getServiceContext());
@@ -1103,7 +1126,9 @@ TEST_F(LockerImplTest, GetLockerInfoShouldReportPendingLocks) {
TEST_F(LockerImplTest, ReaquireLockPendingUnlock) {
auto opCtx = makeOperationContext();
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(opCtx->getServiceContext());
locker.lockGlobal(opCtx.get(), MODE_IS);
@@ -1133,7 +1158,9 @@ TEST_F(LockerImplTest, ReaquireLockPendingUnlock) {
TEST_F(LockerImplTest, AcquireLockPendingUnlockWithCoveredMode) {
auto opCtx = makeOperationContext();
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(opCtx->getServiceContext());
locker.lockGlobal(opCtx.get(), MODE_IS);
@@ -1163,7 +1190,9 @@ TEST_F(LockerImplTest, AcquireLockPendingUnlockWithCoveredMode) {
TEST_F(LockerImplTest, ConvertLockPendingUnlock) {
auto opCtx = makeOperationContext();
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(opCtx->getServiceContext());
locker.lockGlobal(opCtx.get(), MODE_IS);
@@ -1197,7 +1226,9 @@ TEST_F(LockerImplTest, ConvertLockPendingUnlock) {
TEST_F(LockerImplTest, ConvertLockPendingUnlockAndUnlock) {
auto opCtx = makeOperationContext();
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(opCtx->getServiceContext());
locker.lockGlobal(opCtx.get(), MODE_IS);
@@ -1269,7 +1300,9 @@ DEATH_TEST_F(LockerImplTest,
"Operation ending while holding locks.") {
auto opCtx = makeOperationContext();
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "TestDB.collection"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
LockerImpl locker(opCtx->getServiceContext());
locker.lockGlobal(opCtx.get(), MODE_IX);
diff --git a/src/mongo/db/concurrency/lock_stats_test.cpp b/src/mongo/db/concurrency/lock_stats_test.cpp
index 19f13672734..b1a32ddccb1 100644
--- a/src/mongo/db/concurrency/lock_stats_test.cpp
+++ b/src/mongo/db/concurrency/lock_stats_test.cpp
@@ -39,7 +39,9 @@ namespace mongo {
class LockStatsTest : public ServiceContextTest {};
TEST_F(LockStatsTest, NoWait) {
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "LockStats.NoWait"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "LockStats.NoWait"));
resetGlobalLockStats();
@@ -58,7 +60,9 @@ TEST_F(LockStatsTest, NoWait) {
}
TEST_F(LockStatsTest, Wait) {
- const ResourceId resId(RESOURCE_COLLECTION, NamespaceString(boost::none, "LockStats.Wait"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "LockStats.Wait"));
resetGlobalLockStats();
@@ -92,8 +96,9 @@ TEST_F(LockStatsTest, Wait) {
}
TEST_F(LockStatsTest, Reporting) {
- const ResourceId resId(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "LockStats.Reporting"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "LockStats.Reporting"));
resetGlobalLockStats();
@@ -111,8 +116,9 @@ TEST_F(LockStatsTest, Reporting) {
}
TEST_F(LockStatsTest, Subtraction) {
- const ResourceId resId(RESOURCE_COLLECTION,
- NamespaceString(boost::none, "LockStats.Subtraction"));
+ const ResourceId resId(
+ RESOURCE_COLLECTION,
+ NamespaceString::createNamespaceString_forTest(boost::none, "LockStats.Subtraction"));
resetGlobalLockStats();
diff --git a/src/mongo/db/concurrency/resource_catalog_test.cpp b/src/mongo/db/concurrency/resource_catalog_test.cpp
index 99752d3acd4..026e5cf587a 100644
--- a/src/mongo/db/concurrency/resource_catalog_test.cpp
+++ b/src/mongo/db/concurrency/resource_catalog_test.cpp
@@ -41,13 +41,16 @@ public:
}
protected:
- NamespaceString firstCollection{boost::none, "1661880728"};
+ NamespaceString firstCollection =
+ NamespaceString::createNamespaceString_forTest(boost::none, "1661880728");
ResourceId firstResourceId{RESOURCE_COLLECTION, firstCollection};
- NamespaceString secondCollection{boost::none, "1626936312"};
+ NamespaceString secondCollection =
+ NamespaceString::createNamespaceString_forTest(boost::none, "1626936312");
ResourceId secondResourceId{RESOURCE_COLLECTION, secondCollection};
- NamespaceString thirdCollection{boost::none, "2930102946"};
+ NamespaceString thirdCollection =
+ NamespaceString::createNamespaceString_forTest(boost::none, "2930102946");
ResourceId thirdResourceId{RESOURCE_COLLECTION, thirdCollection};
ResourceCatalog catalog;
@@ -81,7 +84,8 @@ TEST_F(ResourceCatalogTest, RemoveTest) {
catalog.add(thirdResourceId, thirdCollection);
// This fails to remove the resource because of an invalid namespace.
- catalog.remove(firstResourceId, NamespaceString(boost::none, "BadNamespace"));
+ catalog.remove(firstResourceId,
+ NamespaceString::createNamespaceString_forTest(boost::none, "BadNamespace"));
auto resource = catalog.name(firstResourceId);
ASSERT_EQ(firstCollection.toStringWithTenantId(), *resource);
@@ -147,7 +151,7 @@ DEATH_TEST_F(ResourceCatalogTest, AddDatabaseInvalidResourceType, "invariant") {
}
DEATH_TEST_F(ResourceCatalogTest, AddCollectionInvalidResourceType, "invariant") {
- catalog.add({RESOURCE_GLOBAL, 0}, NamespaceString{"db.coll"});
+ catalog.add({RESOURCE_GLOBAL, 0}, NamespaceString::createNamespaceString_forTest("db.coll"));
}
} // namespace
} // namespace mongo