[fuzzing] Add TickUntil variants to FuzzingEventEngine (#34308)

Sometimes we just want to wait until a specific time
pull/34317/head
Craig Tiller 2 years ago committed by GitHub
parent 03776a2f3e
commit 3e3c828f91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc
  2. 13
      test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h

@ -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_;

@ -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<FuzzingEventEngine, Duration>;
// 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<std::unique_ptr<Listener>> 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<FuzzingEventEngine, Duration>;
Time Now() ABSL_LOCKS_EXCLUDED(mu_);
// Clear any global hooks installed by this event engine. Call prior to

Loading…
Cancel
Save