summaryrefslogtreecommitdiff
path: root/src/mongo/db/session_catalog_test.cpp
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2018-09-24 16:43:58 -0400
committerSpencer T Brody <spencer@mongodb.com>2018-09-28 13:15:08 -0400
commit9406af079a894bae80fbbec4703b04974bf84476 (patch)
tree3981fb0e4b129713f84cf34b38a7d56001e9f60e /src/mongo/db/session_catalog_test.cpp
parent56aa77807e5ff288635b69c40bf4d201e715051d (diff)
downloadmongo-9406af079a894bae80fbbec4703b04974bf84476.tar.gz
SERVER-35870 Allow more than one thread to block Session checkout at a time
Diffstat (limited to 'src/mongo/db/session_catalog_test.cpp')
-rw-r--r--src/mongo/db/session_catalog_test.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/mongo/db/session_catalog_test.cpp b/src/mongo/db/session_catalog_test.cpp
index e0343f8672a..3efb8a0dcb3 100644
--- a/src/mongo/db/session_catalog_test.cpp
+++ b/src/mongo/db/session_catalog_test.cpp
@@ -276,5 +276,39 @@ TEST_F(SessionCatalogTest, WaitForAllSessions) {
future.get();
}
+TEST_F(SessionCatalogTest, MultiplePreventCheckingOutSessionsBlocks) {
+ const auto lsid1 = makeLogicalSessionIdForTest();
+ opCtx()->setLogicalSessionId(lsid1);
+ opCtx()->setDeadlineAfterNowBy(Milliseconds(10), ErrorCodes::MaxTimeMSExpired);
+
+ boost::optional<OperationContextSession> ocs;
+
+ // Prevent new Sessions from being checked out.
+ boost::optional<SessionCatalog::PreventCheckingOutSessionsBlock> preventCheckoutBlock1,
+ preventCheckoutBlock2;
+ preventCheckoutBlock1.emplace(catalog());
+
+ // Ensure that checking out a Session fails
+ ASSERT_THROWS_CODE(
+ ocs.emplace(opCtx(), true), AssertionException, ErrorCodes::MaxTimeMSExpired);
+
+ // A second request to prevent checking out Sessions is legal.
+ preventCheckoutBlock2.emplace(catalog());
+ ASSERT_THROWS_CODE(
+ ocs.emplace(opCtx(), true), AssertionException, ErrorCodes::MaxTimeMSExpired);
+
+ // The first request completing before the second is valid and doesn't start allowing checkouts.
+ preventCheckoutBlock1.reset();
+ ASSERT_THROWS_CODE(
+ ocs.emplace(opCtx(), true), AssertionException, ErrorCodes::MaxTimeMSExpired);
+
+ // Releasing the last PreventCheckingOutSessionsBlock allows Session checkout to proceed.
+ preventCheckoutBlock2.reset();
+
+ ASSERT_TRUE(ocs == boost::none);
+ ocs.emplace(opCtx(), true);
+ ASSERT_EQ(lsid1, ocs->get(opCtx())->getSessionId());
+}
+
} // namespace
} // namespace mongo