aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/testlib
diff options
context:
space:
mode:
authorsnaury <snaury@ydb.tech>2023-05-16 13:43:28 +0300
committersnaury <snaury@ydb.tech>2023-05-16 13:43:28 +0300
commitc9df7fc86be0b15adc1e812144c41ab5c057baef (patch)
tree63c809b43d9e026188f6a66725ccac433ba0f734 /library/cpp/actors/testlib
parenta2e846788b0a6d372d15ab5de915616cc6bc00ce (diff)
downloadydb-c9df7fc86be0b15adc1e812144c41ab5c057baef.tar.gz
Support monotonic boot time with suspend awareness
Diffstat (limited to 'library/cpp/actors/testlib')
-rw-r--r--library/cpp/actors/testlib/test_runtime.cpp26
-rw-r--r--library/cpp/actors/testlib/test_runtime.h4
2 files changed, 30 insertions, 0 deletions
diff --git a/library/cpp/actors/testlib/test_runtime.cpp b/library/cpp/actors/testlib/test_runtime.cpp
index 6fedca1cd22..2ec0b27ddce 100644
--- a/library/cpp/actors/testlib/test_runtime.cpp
+++ b/library/cpp/actors/testlib/test_runtime.cpp
@@ -246,6 +246,20 @@ namespace NActors {
TTestActorRuntimeBase& Runtime;
};
+ class TTestActorRuntimeBase::TBootTimeProvider : public IBootTimeProvider {
+ public:
+ TBootTimeProvider(TTestActorRuntimeBase& runtime)
+ : Runtime(runtime)
+ { }
+
+ TBootTime Now() override {
+ return Runtime.GetCurrentBootTime();
+ }
+
+ private:
+ TTestActorRuntimeBase& Runtime;
+ };
+
class TTestActorRuntimeBase::TSchedulerThreadStub : public ISchedulerThread {
public:
TSchedulerThreadStub(TTestActorRuntimeBase* runtime, TTestActorRuntimeBase::TNodeDataBase* node)
@@ -496,6 +510,7 @@ namespace NActors {
, RandomProvider(CreateDeterministicRandomProvider(DefaultRandomSeed))
, TimeProvider(new TTimeProvider(*this))
, MonotonicTimeProvider(new TMonotonicTimeProvider(*this))
+ , BootTimeProvider(new TBootTimeProvider(*this))
, ShouldContinue()
, CurrentTimestamp(0)
, DispatchTimeout(DEFAULT_DISPATCH_TIMEOUT)
@@ -829,6 +844,12 @@ namespace NActors {
return TMonotonic::MicroSeconds(CurrentTimestamp);
}
+ TBootTime TTestActorRuntimeBase::GetCurrentBootTime() const {
+ TGuard<TMutex> guard(Mutex);
+ Y_VERIFY(!UseRealThreads);
+ return TBootTime::MicroSeconds(CurrentTimestamp);
+ }
+
void TTestActorRuntimeBase::UpdateCurrentTime(TInstant newTime) {
static int counter = 0;
++counter;
@@ -860,6 +881,11 @@ namespace NActors {
return MonotonicTimeProvider;
}
+ TIntrusivePtr<IBootTimeProvider> TTestActorRuntimeBase::GetBootTimeProvider() {
+ Y_VERIFY(!UseRealThreads);
+ return BootTimeProvider;
+ }
+
ui32 TTestActorRuntimeBase::GetNodeId(ui32 index) const {
Y_VERIFY(index < NodeCount);
return FirstNodeId + index;
diff --git a/library/cpp/actors/testlib/test_runtime.h b/library/cpp/actors/testlib/test_runtime.h
index 0c1e4207cc7..a5d6b3b6e9a 100644
--- a/library/cpp/actors/testlib/test_runtime.h
+++ b/library/cpp/actors/testlib/test_runtime.h
@@ -190,6 +190,7 @@ namespace NActors {
class TExecutorPoolStub;
class TTimeProvider;
class TMonotonicTimeProvider;
+ class TBootTimeProvider;
enum class EEventAction {
PROCESS,
@@ -232,8 +233,10 @@ namespace NActors {
void SetLogPriority(NActors::NLog::EComponent component, NActors::NLog::EPriority priority);
TIntrusivePtr<ITimeProvider> GetTimeProvider();
TIntrusivePtr<IMonotonicTimeProvider> GetMonotonicTimeProvider();
+ TIntrusivePtr<IBootTimeProvider> GetBootTimeProvider();
TInstant GetCurrentTime() const;
TMonotonic GetCurrentMonotonicTime() const;
+ TBootTime GetCurrentBootTime() const;
void UpdateCurrentTime(TInstant newTime);
void AdvanceCurrentTime(TDuration duration);
void AddLocalService(const TActorId& actorId, const TActorSetupCmd& cmd, ui32 nodeIndex = 0);
@@ -549,6 +552,7 @@ namespace NActors {
TIntrusivePtr<IRandomProvider> RandomProvider;
TIntrusivePtr<ITimeProvider> TimeProvider;
TIntrusivePtr<IMonotonicTimeProvider> MonotonicTimeProvider;
+ TIntrusivePtr<IBootTimeProvider> BootTimeProvider;
protected:
struct TNodeDataBase: public TThrRefBase {