diff options
author | Benety Goh <benety@mongodb.com> | 2021-09-29 11:43:30 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-09-29 16:07:55 +0000 |
commit | 4671eda7d4153bd30669b2aba85514d442f69627 (patch) | |
tree | caeb27a9dbeb8def2240e544099a213a9122f4cd /src/mongo/db/concurrency | |
parent | a10b82783a88737d2870ae591184d9a6dd932665 (diff) | |
download | mongo-4671eda7d4153bd30669b2aba85514d442f69627.tar.gz |
SERVER-60275 add LockerNoopClientObserverRegisterer
This registration helper is intended for use in cases where the
a member field requires a ServiceContext to be updated, making it
infeasible to perform the client observer registration in the
constructor body.
Diffstat (limited to 'src/mongo/db/concurrency')
-rw-r--r-- | src/mongo/db/concurrency/locker_noop_service_context_test_fixture.h | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/mongo/db/concurrency/locker_noop_service_context_test_fixture.h b/src/mongo/db/concurrency/locker_noop_service_context_test_fixture.h index ef4394056d3..cffd44150bd 100644 --- a/src/mongo/db/concurrency/locker_noop_service_context_test_fixture.h +++ b/src/mongo/db/concurrency/locker_noop_service_context_test_fixture.h @@ -35,17 +35,31 @@ namespace mongo { /** + * Registers the LockerNoopClientObserver with the provided ServiceContext on construction. + */ +class LockerNoopClientObserverRegisterer { + LockerNoopClientObserverRegisterer(const LockerNoopClientObserverRegisterer&) = delete; + LockerNoopClientObserverRegisterer& operator=(const LockerNoopClientObserverRegisterer&) = + delete; + +public: + explicit LockerNoopClientObserverRegisterer(ServiceContext* service) { + service->registerClientObserver(std::make_unique<LockerNoopClientObserver>()); + } +}; + +/** * Test fixture for tests that require a properly initialized global service context * and a stub Locker implementation whenever an OperationContext is requested. */ class LockerNoopServiceContextTest : public ServiceContextTest { protected: - LockerNoopServiceContextTest() { - auto service = getServiceContext(); - service->registerClientObserver(std::make_unique<LockerNoopClientObserver>()); - } + LockerNoopServiceContextTest() : _lockerNoopClientObserverRegisterer(getServiceContext()) {} ~LockerNoopServiceContextTest() = default; + +private: + LockerNoopClientObserverRegisterer _lockerNoopClientObserverRegisterer; }; } // namespace mongo |