summaryrefslogtreecommitdiff
path: root/src/mongo/db/concurrency/d_concurrency_test.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2017-07-25 18:03:40 -0400
committerBenety Goh <benety@mongodb.com>2017-09-19 15:07:58 -0400
commit0e2b48d8dd77f972449b89869cdbfabdbc074845 (patch)
treedd2fce9f35059da72e89d61e137127412b254a86 /src/mongo/db/concurrency/d_concurrency_test.cpp
parentdde9b54199fe375977f2721258620191079c8abb (diff)
downloadmongo-0e2b48d8dd77f972449b89869cdbfabdbc074845.tar.gz
SERVER-30530 WCE retry loop runs argument function without retry logic if in a WUOW
If there's already a WUOW, we assume that we are already running in a WCE retry up the call stack.
Diffstat (limited to 'src/mongo/db/concurrency/d_concurrency_test.cpp')
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index d4dcc226635..ac7eada9693 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -164,7 +164,47 @@ private:
TEST_F(DConcurrencyTestFixture, WriteConflictRetryInstantiatesOK) {
- writeConflictRetry(nullptr, "", "", [] {});
+ auto opCtx = makeOpCtx();
+ opCtx->setLockState(stdx::make_unique<MMAPV1LockerImpl>());
+ writeConflictRetry(opCtx.get(), "", "", [] {});
+}
+
+TEST_F(DConcurrencyTestFixture, WriteConflictRetryRetriesFunctionOnWriteConflictException) {
+ auto opCtx = makeOpCtx();
+ opCtx->setLockState(stdx::make_unique<MMAPV1LockerImpl>());
+ auto&& opDebug = CurOp::get(opCtx.get())->debug();
+ ASSERT_EQUALS(0LL, opDebug.writeConflicts);
+ ASSERT_EQUALS(100, writeConflictRetry(opCtx.get(), "", "", [&opDebug] {
+ if (opDebug.writeConflicts == 0LL) {
+ throw WriteConflictException();
+ }
+ return 100;
+ }));
+ ASSERT_EQUALS(1LL, opDebug.writeConflicts);
+}
+
+TEST_F(DConcurrencyTestFixture, WriteConflictRetryPropagatesNonWriteConflictException) {
+ auto opCtx = makeOpCtx();
+ opCtx->setLockState(stdx::make_unique<MMAPV1LockerImpl>());
+ ASSERT_THROWS_CODE(writeConflictRetry(opCtx.get(),
+ "",
+ "",
+ [] {
+ uassert(ErrorCodes::OperationFailed, "", false);
+ MONGO_UNREACHABLE;
+ }),
+ AssertionException,
+ ErrorCodes::OperationFailed);
+}
+
+TEST_F(DConcurrencyTestFixture,
+ WriteConflictRetryPropagatesWriteConflictExceptionIfAlreadyInAWriteUnitOfWork) {
+ auto opCtx = makeOpCtx();
+ opCtx->setLockState(stdx::make_unique<MMAPV1LockerImpl>());
+ Lock::GlobalWrite globalWrite(opCtx.get());
+ WriteUnitOfWork wuow(opCtx.get());
+ ASSERT_THROWS(writeConflictRetry(opCtx.get(), "", "", [] { throw WriteConflictException(); }),
+ WriteConflictException);
}
TEST_F(DConcurrencyTestFixture, ResourceMutex) {