diff options
| author | Alexey Borzenkov <[email protected]> | 2022-03-18 00:56:45 +0300 |
|---|---|---|
| committer | Alexey Borzenkov <[email protected]> | 2022-03-18 00:56:45 +0300 |
| commit | 2fbdf1c88f149f6e23c2363c649cda6f8ff21c92 (patch) | |
| tree | 08a155f1ac2475bc52552a138044722e7a16b23b /library/cpp/actors/testlib/test_runtime.cpp | |
| parent | 47f097013d31b097f97ed0981092273bcc79ae58 (diff) | |
Add monotonic time provider, KIKIMR-13910
ref:72823653cdfd5fb04f1f1a001374fc120b3da7af
Diffstat (limited to 'library/cpp/actors/testlib/test_runtime.cpp')
| -rw-r--r-- | library/cpp/actors/testlib/test_runtime.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/library/cpp/actors/testlib/test_runtime.cpp b/library/cpp/actors/testlib/test_runtime.cpp index 6fa25b99656..51d93ba6e93 100644 --- a/library/cpp/actors/testlib/test_runtime.cpp +++ b/library/cpp/actors/testlib/test_runtime.cpp @@ -233,6 +233,20 @@ namespace NActors { TTestActorRuntimeBase& Runtime; }; + class TTestActorRuntimeBase::TMonotonicTimeProvider : public IMonotonicTimeProvider { + public: + TMonotonicTimeProvider(TTestActorRuntimeBase& runtime) + : Runtime(runtime) + { } + + TMonotonic Now() override { + return Runtime.GetCurrentMonotonicTime(); + } + + private: + TTestActorRuntimeBase& Runtime; + }; + class TTestActorRuntimeBase::TSchedulerThreadStub : public ISchedulerThread { public: TSchedulerThreadStub(TTestActorRuntimeBase* runtime, TTestActorRuntimeBase::TNodeDataBase* node) @@ -470,6 +484,7 @@ namespace NActors { , NeedMonitoring(false) , RandomProvider(CreateDeterministicRandomProvider(DefaultRandomSeed)) , TimeProvider(new TTimeProvider(*this)) + , MonotonicTimeProvider(new TMonotonicTimeProvider(*this)) , ShouldContinue() , CurrentTimestamp(0) , DispatchTimeout(DEFAULT_DISPATCH_TIMEOUT) @@ -797,6 +812,12 @@ namespace NActors { return TInstant::MicroSeconds(CurrentTimestamp); } + TMonotonic TTestActorRuntimeBase::GetCurrentMonotonicTime() const { + TGuard<TMutex> guard(Mutex); + Y_VERIFY(!UseRealThreads); + return TMonotonic::MicroSeconds(CurrentTimestamp); + } + void TTestActorRuntimeBase::UpdateCurrentTime(TInstant newTime) { static int counter = 0; ++counter; @@ -823,6 +844,11 @@ namespace NActors { return TimeProvider; } + TIntrusivePtr<IMonotonicTimeProvider> TTestActorRuntimeBase::GetMonotonicTimeProvider() { + Y_VERIFY(!UseRealThreads); + return MonotonicTimeProvider; + } + ui32 TTestActorRuntimeBase::GetNodeId(ui32 index) const { Y_VERIFY(index < NodeCount); return FirstNodeId + index; |
