diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2018-03-08 17:53:51 -0500 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2018-03-14 14:18:23 -0400 |
commit | 5436b257da849bfe91934d904b5fcf27ccfdd366 (patch) | |
tree | ee6b2dde2a1ae04f4a9afd23add01f0fe59ce054 /src/mongo/db/session_catalog_test.cpp | |
parent | b5b4975daf0a327cc2ee2756b6771ca4c9fabfed (diff) | |
download | mongo-5436b257da849bfe91934d904b5fcf27ccfdd366.tar.gz |
SERVER-33672 Make killSessionsLocal() kill any matching Sessions
Diffstat (limited to 'src/mongo/db/session_catalog_test.cpp')
-rw-r--r-- | src/mongo/db/session_catalog_test.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/mongo/db/session_catalog_test.cpp b/src/mongo/db/session_catalog_test.cpp index 1dd009479fd..a02203e5554 100644 --- a/src/mongo/db/session_catalog_test.cpp +++ b/src/mongo/db/session_catalog_test.cpp @@ -278,5 +278,41 @@ TEST_F(SessionCatalogTest, OnlyCheckOutSessionWithCheckOutSessionTrue) { } } +TEST_F(SessionCatalogTest, ScanSessions) { + std::vector<LogicalSessionId> lsids; + auto workerFn = [&](OperationContext* opCtx, Session* session) { + lsids.push_back(session->getSessionId()); + }; + + // Scan over zero Sessions. + SessionKiller::Matcher matcherAllSessions( + KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(opCtx())}); + catalog()->scanSessions(opCtx(), matcherAllSessions, workerFn); + ASSERT(lsids.empty()); + + // Create three sessions in the catalog. + auto lsid1 = makeLogicalSessionIdForTest(); + auto lsid2 = makeLogicalSessionIdForTest(); + auto lsid3 = makeLogicalSessionIdForTest(); + { + auto scopedSession1 = catalog()->getOrCreateSession(opCtx(), lsid1); + auto scopedSession2 = catalog()->getOrCreateSession(opCtx(), lsid2); + auto scopedSession3 = catalog()->getOrCreateSession(opCtx(), lsid3); + } + + // Scan over all Sessions. + lsids.clear(); + catalog()->scanSessions(opCtx(), matcherAllSessions, workerFn); + ASSERT_EQ(lsids.size(), 3U); + + // Scan over all Sessions, visiting a particular Session. + SessionKiller::Matcher matcherLSID2( + KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(opCtx(), lsid2)}); + lsids.clear(); + catalog()->scanSessions(opCtx(), matcherLSID2, workerFn); + ASSERT_EQ(lsids.size(), 1U); + ASSERT_EQ(lsids.front(), lsid2); +} + } // namespace } // namespace mongo |