diff --git a/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc b/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc index 36dcfa5f029..b3ea892faa1 100644 --- a/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc +++ b/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc @@ -180,6 +180,28 @@ void FuzzingEventEngine::TickUntilIdle() { } } +void FuzzingEventEngine::TickUntil(Time t) { + while (true) { + auto now = Now(); + if (now >= t) break; + Tick(t - now); + } +} + +void FuzzingEventEngine::TickUntilTimespec(gpr_timespec t) { + GPR_ASSERT(t.clock_type != GPR_TIMESPAN); + TickUntil(Time() + std::chrono::seconds(t.tv_sec) + + std::chrono::nanoseconds(t.tv_nsec)); +} + +void FuzzingEventEngine::TickUntilTimestamp(grpc_core::Timestamp t) { + TickUntilTimespec(t.as_timespec(GPR_CLOCK_REALTIME)); +} + +void FuzzingEventEngine::TickForDuration(grpc_core::Duration d) { + TickUntilTimestamp(grpc_core::Timestamp::Now() + d); +} + FuzzingEventEngine::Time FuzzingEventEngine::Now() { grpc_core::MutexLock lock(&*now_mu_); return now_; diff --git a/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h b/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h index 936d926ddfb..6a1c34f3150 100644 --- a/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h +++ b/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h @@ -41,6 +41,7 @@ #include "src/core/lib/gprpp/no_destruct.h" #include "src/core/lib/gprpp/sync.h" +#include "src/core/lib/gprpp/time.h" #include "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.h" #include "test/core/util/port.h" @@ -59,6 +60,8 @@ class FuzzingEventEngine : public EventEngine { const fuzzing_event_engine::Actions& actions); ~FuzzingEventEngine() override { UnsetGlobalHooks(); } + using Time = std::chrono::time_point; + // Once the fuzzing work is completed, this method should be called to speed // quiescence. void FuzzingDone() ABSL_LOCKS_EXCLUDED(mu_); @@ -67,6 +70,14 @@ class FuzzingEventEngine : public EventEngine { ABSL_LOCKS_EXCLUDED(mu_); // Repeatedly call Tick() until there is no more work to do. void TickUntilIdle() ABSL_LOCKS_EXCLUDED(mu_); + // Tick until some time + void TickUntil(Time t) ABSL_LOCKS_EXCLUDED(mu_); + // Tick until some gpr_timespec + void TickUntilTimespec(gpr_timespec t) ABSL_LOCKS_EXCLUDED(mu_); + // Tick until some grpc_core::Timestamp + void TickUntilTimestamp(grpc_core::Timestamp t) ABSL_LOCKS_EXCLUDED(mu_); + // Tick for some grpc_core::Duration + void TickForDuration(grpc_core::Duration d) ABSL_LOCKS_EXCLUDED(mu_); absl::StatusOr> CreateListener( Listener::AcceptCallback on_accept, @@ -97,8 +108,6 @@ class FuzzingEventEngine : public EventEngine { ABSL_LOCKS_EXCLUDED(mu_) override; bool Cancel(TaskHandle handle) ABSL_LOCKS_EXCLUDED(mu_) override; - using Time = std::chrono::time_point; - Time Now() ABSL_LOCKS_EXCLUDED(mu_); // Clear any global hooks installed by this event engine. Call prior to