diff options
author | Ben Caimano <ben.caimano@10gen.com> | 2020-07-23 21:59:46 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-07-28 20:57:56 +0000 |
commit | 214379825c248f5a5e5f0a01ad9863b900faaf30 (patch) | |
tree | 077a4844ec0daaf1a738933920525cde7d440131 /src/mongo/executor | |
parent | 6dd301449ec7a48e35a7114e93b888df9958217f (diff) | |
download | mongo-214379825c248f5a5e5f0a01ad9863b900faaf30.tar.gz |
SERVER-48650 Gave the ClockSourceMock a global impl
Diffstat (limited to 'src/mongo/executor')
-rw-r--r-- | src/mongo/executor/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_mock.cpp | 22 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_mock.h | 29 |
3 files changed, 17 insertions, 35 deletions
diff --git a/src/mongo/executor/SConscript b/src/mongo/executor/SConscript index 80ee3174a12..da4acd722ab 100644 --- a/src/mongo/executor/SConscript +++ b/src/mongo/executor/SConscript @@ -74,6 +74,7 @@ env.Library('network_interface_mock', LIBDEPS=[ '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/rpc/metadata', + '$BUILD_DIR/mongo/util/clock_source_mock', '$BUILD_DIR/mongo/util/net/network', 'network_interface', 'task_executor_interface', diff --git a/src/mongo/executor/network_interface_mock.cpp b/src/mongo/executor/network_interface_mock.cpp index ab1fcceb126..ed9e7fe1d4d 100644 --- a/src/mongo/executor/network_interface_mock.cpp +++ b/src/mongo/executor/network_interface_mock.cpp @@ -50,9 +50,9 @@ using CallbackHandle = TaskExecutor::CallbackHandle; using ResponseStatus = TaskExecutor::ResponseStatus; NetworkInterfaceMock::NetworkInterfaceMock() - : _waitingToRunMask(0), + : _clkSource(std::make_unique<ClockSourceMock>()), + _waitingToRunMask(0), _currentlyRunning(kNoThread), - _now(fassert(18653, dateFromISOString("2014-08-01T00:00:00Z"))), _hasStarted(false), _inShutdown(false), _executorNextWakeupDate(Date_t::max()) {} @@ -416,8 +416,11 @@ Date_t NetworkInterfaceMock::runUntil(Date_t until) { if (until < newNow) { newNow = until; } - invariant(_now_inlock() <= newNow); - _now = newNow; + + auto duration = newNow - _now_inlock(); + invariant(duration >= Milliseconds{0}); + _clkSource->advance(duration); + _waitingToRunMask |= kExecutorThread; } _runReadyNetworkOperations_inlock(&lk); @@ -427,8 +430,10 @@ Date_t NetworkInterfaceMock::runUntil(Date_t until) { void NetworkInterfaceMock::advanceTime(Date_t newTime) { stdx::unique_lock<stdx::mutex> lk(_mutex); invariant(_currentlyRunning == kNetworkThread); - invariant(newTime > _now_inlock()); - _now = newTime; + + auto duration = newTime - _now_inlock(); + invariant(duration > Milliseconds{0}); + _clkSource->advance(duration); _waitingToRunMask |= kExecutorThread; _runReadyNetworkOperations_inlock(&lk); @@ -720,10 +725,5 @@ NetworkInterfaceMock* NetworkInterfaceMock::InNetworkGuard::operator->() const { return _net; } -NetworkInterfaceMockClockSource::NetworkInterfaceMockClockSource(NetworkInterfaceMock* net) - : _net(net) { - _tracksSystemClock = false; -} - } // namespace executor } // namespace mongo diff --git a/src/mongo/executor/network_interface_mock.h b/src/mongo/executor/network_interface_mock.h index 8781101329d..911917523fc 100644 --- a/src/mongo/executor/network_interface_mock.h +++ b/src/mongo/executor/network_interface_mock.h @@ -42,6 +42,7 @@ #include "mongo/stdx/unordered_map.h" #include "mongo/stdx/unordered_set.h" #include "mongo/util/clock_source.h" +#include "mongo/util/clock_source_mock.h" #include "mongo/util/time_support.h" namespace mongo { @@ -319,7 +320,7 @@ private: * Returns the current virtualized time. */ Date_t _now_inlock() const { - return _now; + return _clkSource->now(); } /** @@ -364,6 +365,9 @@ private: // in multi-threaded execution, and so unsynchronized, are labeled (R). stdx::mutex _mutex; // NOLINT + // A mocked clock source. + std::unique_ptr<ClockSourceMock> _clkSource; // (M) + // Condition signaled to indicate that the network processing thread should wake up. stdx::condition_variable _shouldWakeNetworkCondition; // (M) @@ -376,9 +380,6 @@ private: // Indicator of which thread, if any, is currently running. ThreadType _currentlyRunning; // (M) - // The current time reported by this instance of NetworkInterfaceMock. - Date_t _now; // (M) - // Set to true by "startUp()" bool _hasStarted; // (M) @@ -556,25 +557,5 @@ private: bool _callExitNetwork = true; }; -class NetworkInterfaceMockClockSource : public ClockSource { -public: - explicit NetworkInterfaceMockClockSource(NetworkInterfaceMock* net); - - Milliseconds getPrecision() override { - return Milliseconds{1}; - } - Date_t now() override { - return _net->now(); - } - Status setAlarm(Date_t when, unique_function<void()> action) override { - return _net->setAlarm(TaskExecutor::CallbackHandle(), - when, - [action = std::move(action)](Status) { action(); }); - } - -private: - NetworkInterfaceMock* _net; -}; - } // namespace executor } // namespace mongo |