summaryrefslogtreecommitdiff
path: root/src/mongo/db/concurrency/d_concurrency_test.cpp
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2018-06-22 12:00:21 -0400
committerAndy Schwerin <schwerin@mongodb.com>2018-06-22 12:32:29 -0400
commitd520be0814492c262515cf0a5d62a127ace70dce (patch)
treee754e3cce243a7b51922b6d2a179a3d355ccefb7 /src/mongo/db/concurrency/d_concurrency_test.cpp
parentc0b942e3a80b9ccd8434ab0927d97cbd1862d19a (diff)
downloadmongo-d520be0814492c262515cf0a5d62a127ace70dce.tar.gz
SERVER-34798 Remove ServiceContext subclasses and use new ServiceContext in every unit test.
This patch does several loosely related and surprisingly hard to separate things. 1.) Make the ServiceContext class final 2.) Create a mechanism, called ConstructorActions, for running methods on ServiceContexts immediately after they're built and immediately before they're destroyed. 3.) Introduce / improve test fixture base classes for tests, giving them fresh ServiceContext instances for each test case. There is one fixture for tests that need a storage engine and another for those that do not. 4.) Make several remaining global variables SC decorations in support of (3) 5.) Replace many MONGO_INITIALIZERS that access getGlobalServiceContext with the new constructor-actions system, which is needed for (3.) 6.) Fix up tests to use the fixtures from (3) and fix tests that silently used different service contexts in together in a technically illegal fashion that now breaks. 7.) Utilize (2) as necessary to simplify initialization of new ServiceContexts, simplifying the fixtures in (3).
Diffstat (limited to 'src/mongo/db/concurrency/d_concurrency_test.cpp')
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp69
1 files changed, 28 insertions, 41 deletions
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index 2be5c7c33d5..145f4f31846 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/concurrency/global_lock_acquisition_tracker.h"
#include "mongo/db/concurrency/lock_manager_test_help.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
+#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/db/storage/recovery_unit_noop.h"
#include "mongo/stdx/functional.h"
#include "mongo/stdx/future.h"
@@ -77,19 +78,8 @@ private:
};
-class DConcurrencyTestFixture : public unittest::Test {
+class DConcurrencyTestFixture : public ServiceContextMongoDTest {
public:
- DConcurrencyTestFixture() : _client(getGlobalServiceContext()->makeClient("testClient")) {}
- ~DConcurrencyTestFixture() {}
-
- /**
- * Constructs and returns a new OperationContext.
- */
- ServiceContext::UniqueOperationContext makeOpCtx() const {
- auto opCtx = _client->makeOperationContext();
- return opCtx;
- }
-
/**
* Returns a vector of Clients of length 'k', each of which has an OperationContext with its
* lockState set to a DefaultLockerImpl.
@@ -101,8 +91,8 @@ public:
clients;
clients.reserve(k);
for (int i = 0; i < k; ++i) {
- auto client = getGlobalServiceContext()->makeClient(
- str::stream() << "test client for thread " << i);
+ auto client =
+ getServiceContext()->makeClient(str::stream() << "test client for thread " << i);
auto opCtx = client->makeOperationContext();
opCtx->swapLockState(stdx::make_unique<LockerType>());
clients.emplace_back(std::move(client), std::move(opCtx));
@@ -129,20 +119,17 @@ public:
return result;
}
-
-private:
- ServiceContext::UniqueClient _client;
};
TEST_F(DConcurrencyTestFixture, WriteConflictRetryInstantiatesOK) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
writeConflictRetry(opCtx.get(), "", "", [] {});
}
TEST_F(DConcurrencyTestFixture, WriteConflictRetryRetriesFunctionOnWriteConflictException) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
auto&& opDebug = CurOp::get(opCtx.get())->debug();
ASSERT_EQUALS(0LL, opDebug.writeConflicts);
@@ -156,7 +143,7 @@ TEST_F(DConcurrencyTestFixture, WriteConflictRetryRetriesFunctionOnWriteConflict
}
TEST_F(DConcurrencyTestFixture, WriteConflictRetryPropagatesNonWriteConflictException) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
ASSERT_THROWS_CODE(writeConflictRetry(opCtx.get(),
"",
@@ -171,7 +158,7 @@ TEST_F(DConcurrencyTestFixture, WriteConflictRetryPropagatesNonWriteConflictExce
TEST_F(DConcurrencyTestFixture,
WriteConflictRetryPropagatesWriteConflictExceptionIfAlreadyInAWriteUnitOfWork) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
Lock::GlobalWrite globalWrite(opCtx.get());
WriteUnitOfWork wuow(opCtx.get());
@@ -262,21 +249,21 @@ TEST_F(DConcurrencyTestFixture, ResourceMutex) {
}
TEST_F(DConcurrencyTestFixture, GlobalRead) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
Lock::GlobalRead globalRead(opCtx.get());
ASSERT(opCtx->lockState()->isR());
}
TEST_F(DConcurrencyTestFixture, GlobalWrite) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
Lock::GlobalWrite globalWrite(opCtx.get());
ASSERT(opCtx->lockState()->isW());
}
TEST_F(DConcurrencyTestFixture, GlobalWriteAndGlobalRead) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
auto lockState = opCtx->lockState();
@@ -293,7 +280,7 @@ TEST_F(DConcurrencyTestFixture, GlobalWriteAndGlobalRead) {
TEST_F(DConcurrencyTestFixture,
GlobalWriteRequiresExplicitDowngradeToIntentWriteModeIfDestroyedWhileHoldingDatabaseLock) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
auto lockState = opCtx->lockState();
@@ -341,7 +328,7 @@ TEST_F(DConcurrencyTestFixture,
TEST_F(DConcurrencyTestFixture,
GlobalWriteRequiresSupportsDowngradeToIntentWriteModeWhileHoldingDatabaseLock) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
auto lockState = opCtx->lockState();
@@ -388,7 +375,7 @@ TEST_F(DConcurrencyTestFixture,
TEST_F(DConcurrencyTestFixture,
NestedGlobalWriteSupportsDowngradeToIntentWriteModeWhileHoldingDatabaseLock) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
auto lockState = opCtx->lockState();
@@ -595,7 +582,7 @@ TEST_F(DConcurrencyTestFixture, GlobalLockX_TimeoutDueToGlobalLockX) {
}
TEST_F(DConcurrencyTestFixture, TempReleaseGlobalWrite) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
auto lockState = opCtx->lockState();
Lock::GlobalWrite globalWrite(opCtx.get());
@@ -609,7 +596,7 @@ TEST_F(DConcurrencyTestFixture, TempReleaseGlobalWrite) {
}
TEST_F(DConcurrencyTestFixture, TempReleaseRecursive) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
auto lockState = opCtx->lockState();
Lock::GlobalWrite globalWrite(opCtx.get());
@@ -825,7 +812,7 @@ TEST_F(DConcurrencyTestFixture, DBLockWaitIsNotInterruptibleWithLockGuard) {
TEST_F(DConcurrencyTestFixture, DBLockTakesS) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
Lock::DBLock dbRead(opCtx.get(), "db", MODE_S);
@@ -834,7 +821,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesS) {
}
TEST_F(DConcurrencyTestFixture, DBLockTakesX) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
Lock::DBLock dbWrite(opCtx.get(), "db", MODE_X);
@@ -843,7 +830,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesX) {
}
TEST_F(DConcurrencyTestFixture, DBLockTakesISForAdminIS) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
Lock::DBLock dbRead(opCtx.get(), "admin", MODE_IS);
@@ -851,7 +838,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesISForAdminIS) {
}
TEST_F(DConcurrencyTestFixture, DBLockTakesSForAdminS) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
Lock::DBLock dbRead(opCtx.get(), "admin", MODE_S);
@@ -859,7 +846,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesSForAdminS) {
}
TEST_F(DConcurrencyTestFixture, DBLockTakesXForAdminIX) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
Lock::DBLock dbWrite(opCtx.get(), "admin", MODE_IX);
@@ -867,7 +854,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesXForAdminIX) {
}
TEST_F(DConcurrencyTestFixture, DBLockTakesXForAdminX) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
Lock::DBLock dbWrite(opCtx.get(), "admin", MODE_X);
@@ -875,7 +862,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesXForAdminX) {
}
TEST_F(DConcurrencyTestFixture, MultipleWriteDBLocksOnSameThread) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
Lock::DBLock r1(opCtx.get(), "db1", MODE_X);
Lock::DBLock r2(opCtx.get(), "db1", MODE_X);
@@ -884,7 +871,7 @@ TEST_F(DConcurrencyTestFixture, MultipleWriteDBLocksOnSameThread) {
}
TEST_F(DConcurrencyTestFixture, MultipleConflictingDBLocksOnSameThread) {
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
auto lockState = opCtx->lockState();
Lock::DBLock r1(opCtx.get(), "db1", MODE_X);
@@ -897,7 +884,7 @@ TEST_F(DConcurrencyTestFixture, MultipleConflictingDBLocksOnSameThread) {
TEST_F(DConcurrencyTestFixture, IsDbLockedForSMode) {
const std::string dbName("db");
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
auto lockState = opCtx->lockState();
Lock::DBLock dbLock(opCtx.get(), dbName, MODE_S);
@@ -911,7 +898,7 @@ TEST_F(DConcurrencyTestFixture, IsDbLockedForSMode) {
TEST_F(DConcurrencyTestFixture, IsDbLockedForXMode) {
const std::string dbName("db");
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
auto lockState = opCtx->lockState();
Lock::DBLock dbLock(opCtx.get(), dbName, MODE_X);
@@ -925,7 +912,7 @@ TEST_F(DConcurrencyTestFixture, IsDbLockedForXMode) {
TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IS) {
const std::string ns("db1.coll");
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
auto lockState = opCtx->lockState();
@@ -956,7 +943,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IS) {
TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IX) {
const std::string ns("db1.coll");
- auto opCtx = makeOpCtx();
+ auto opCtx = makeOperationContext();
opCtx->swapLockState(stdx::make_unique<MMAPV1LockerImpl>());
auto lockState = opCtx->lockState();