diff options
Diffstat (limited to 'src/mongo/db/logical_session_cache_test.cpp')
-rw-r--r-- | src/mongo/db/logical_session_cache_test.cpp | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/src/mongo/db/logical_session_cache_test.cpp b/src/mongo/db/logical_session_cache_test.cpp index 98d3df0d000..37256c26670 100644 --- a/src/mongo/db/logical_session_cache_test.cpp +++ b/src/mongo/db/logical_session_cache_test.cpp @@ -39,8 +39,9 @@ #include "mongo/db/logical_session_cache.h" #include "mongo/db/logical_session_id.h" #include "mongo/db/logical_session_id_helpers.h" -#include "mongo/db/operation_context_noop.h" -#include "mongo/db/service_context_noop.h" +#include "mongo/db/operation_context.h" +#include "mongo/db/service_context.h" +#include "mongo/db/service_context_test_fixture.h" #include "mongo/db/service_liaison_mock.h" #include "mongo/db/sessions_collection_mock.h" #include "mongo/stdx/future.h" @@ -62,35 +63,25 @@ using unittest::EnsureFCV; * Test fixture that sets up a session cache attached to a mock service liaison * and mock sessions collection implementation. */ -class LogicalSessionCacheTest : public unittest::Test { +class LogicalSessionCacheTest : public ServiceContextTest { public: LogicalSessionCacheTest() : _service(std::make_shared<MockServiceLiaisonImpl>()), - _sessions(std::make_shared<MockSessionsCollectionImpl>()) {} + _sessions(std::make_shared<MockSessionsCollectionImpl>()) { - void setUp() override { - AuthorizationManager::set(&serviceContext, AuthorizationManager::create()); - - auto client = serviceContext.makeClient("testClient"); - _opCtx = client->makeOperationContext(); - _client = client.get(); - Client::setCurrent(std::move(client)); + AuthorizationManager::set(getServiceContext(), AuthorizationManager::create()); + // Re-initialize the client after setting the AuthorizationManager to get an + // AuthorizationSession. + Client::releaseCurrent(); + Client::initThread(getThreadName()); + _opCtx = makeOperationContext(); auto mockService = stdx::make_unique<MockServiceLiaison>(_service); auto mockSessions = stdx::make_unique<MockSessionsCollection>(_sessions); _cache = stdx::make_unique<LogicalSessionCacheImpl>( std::move(mockService), std::move(mockSessions), nullptr); } - void tearDown() override { - if (_opCtx) { - _opCtx.reset(); - } - - _service->join(); - auto client = Client::releaseCurrent(); - } - void waitUntilRefreshScheduled() { while (service()->jobs() < 2) { sleepmillis(10); @@ -110,7 +101,7 @@ public: } void setOpCtx() { - _opCtx = client()->makeOperationContext(); + _opCtx = getClient()->makeOperationContext(); } void clearOpCtx() { @@ -121,20 +112,13 @@ public: return _opCtx.get(); } - Client* client() { - return _client; - } - private: - ServiceContextNoop serviceContext; ServiceContext::UniqueOperationContext _opCtx; std::shared_ptr<MockServiceLiaisonImpl> _service; std::shared_ptr<MockSessionsCollectionImpl> _sessions; std::unique_ptr<LogicalSessionCache> _cache; - - Client* _client; }; // Test that the getFromCache method does not make calls to the sessions collection @@ -205,7 +189,7 @@ TEST_F(LogicalSessionCacheTest, StartSession) { // Do refresh, cached records should get flushed to collection. clearOpCtx(); - ASSERT(cache()->refreshNow(client()).isOK()); + ASSERT(cache()->refreshNow(getClient()).isOK()); ASSERT(sessions()->has(lsid)); // Try to start the same session again, should succeed. @@ -237,7 +221,7 @@ TEST_F(LogicalSessionCacheTest, BasicSessionExpiration) { service()->fastForward(Milliseconds(kSessionTimeout.count() + 5)); // Check that it is no longer in the cache - ASSERT(cache()->refreshNow(client()).isOK()); + ASSERT(cache()->refreshNow(getClient()).isOK()); res = cache()->promote(record.getId()); // TODO SERVER-29709 // ASSERT(!res.isOK()); @@ -260,7 +244,7 @@ TEST_F(LogicalSessionCacheTest, ManySignedLsidsInCacheRefresh) { // Force a refresh clearOpCtx(); service()->fastForward(kForceRefresh); - ASSERT(cache()->refreshNow(client()).isOK()); + ASSERT(cache()->refreshNow(getClient()).isOK()); } // @@ -378,7 +362,7 @@ TEST_F(LogicalSessionCacheTest, RefreshMatrixSessionState) { // Force a refresh clearOpCtx(); service()->fastForward(kForceRefresh); - ASSERT(cache()->refreshNow(client()).isOK()); + ASSERT(cache()->refreshNow(getClient()).isOK()); for (int i = 0; i < 32; i++) { std::stringstream failText; |