1#include <test/csf/Scheduler.h>
3#include <xrpl/beast/unit_test/suite.h>
15 using namespace std::chrono_literals;
19 scheduler.
in(1s, [&] { seen.
insert(1); });
20 scheduler.
in(2s, [&] { seen.
insert(2); });
22 scheduler.
at(scheduler.
now() + 4s, [&] { seen.insert(4); });
23 scheduler.
at(scheduler.
now() + 8s, [&] { seen.insert(8); });
25 auto start = scheduler.
now();
28 BEAST_EXPECT(seen.
empty());
29 BEAST_EXPECT(scheduler.
stepOne());
31 BEAST_EXPECT(scheduler.
now() == (start + 1s));
36 BEAST_EXPECT(scheduler.
now() == (start + 1s));
39 BEAST_EXPECT(scheduler.
stepFor(1s));
41 BEAST_EXPECT(scheduler.
now() == (start + 2s));
45 BEAST_EXPECT(scheduler.
stepFor(1s));
47 BEAST_EXPECT(scheduler.
now() == (start + 3s));
50 BEAST_EXPECT(scheduler.
stepWhile([&]() { return seen.size() < 3; }));
52 BEAST_EXPECT(scheduler.
now() == (start + 4s));
55 BEAST_EXPECT(scheduler.
step());
57 BEAST_EXPECT(scheduler.
now() == (start + 8s));
60 BEAST_EXPECT(!scheduler.
step());
62 BEAST_EXPECT(scheduler.
now() == (start + 8s));
void run() override
Runs the suite.
Simulated discrete-event scheduler.
bool step()
Run the scheduler until no events remain.
CancelToken at(time_point const &when, Function &&f)
Schedule an event at a specific time.
time_point now() const
Return the current network time.
bool stepUntil(time_point const &until)
Run the scheduler until the specified time.
void cancel(CancelToken const &token)
Cancel a timer.
CancelToken in(duration const &delay, Function &&f)
Schedule an event after a specified duration passes.
bool stepOne()
Run the scheduler for up to one event.
bool stepWhile(Function &&func)
Run the scheduler while a condition is true.
bool stepFor(std::chrono::duration< Period, Rep > const &amount)
Run the scheduler until time has elapsed.
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.