diff --git a/src/ripple/basics/chrono.h b/src/ripple/basics/chrono.h index b298ac3f8..b9531cf43 100644 --- a/src/ripple/basics/chrono.h +++ b/src/ripple/basics/chrono.h @@ -39,19 +39,6 @@ using weeks = std::chrono::duration >>; -/** A clock for measuring elapsed time. - - The epoch is unspecified. -*/ -using Stopwatch = - beast::abstract_clock< - std::chrono::steady_clock>; - -/** A manual clock for unit tests. */ -using TestClock = - beast::manual_clock< - Stopwatch::clock_type>; - /** Clock for measuring Ripple Network Time. The epoch is January 1, 2000 @@ -77,9 +64,40 @@ public: std::chrono::time_point< NetClock, duration>; - // VFALCO now() intentionally omitted for the moment + static bool const /* constexpr? */ is_steady = + std::chrono::system_clock::is_steady; + + static + time_point + now() + { + using namespace std; + auto const when = + chrono::system_clock::now(); + return time_point( + chrono::duration_cast( + when.time_since_epoch() - + days(10957))); + } }; +/** A manual NetClock for unit tests. */ +using TestNetClock = + beast::manual_clock; + +/** A clock for measuring elapsed time. + + The epoch is unspecified. +*/ +using Stopwatch = + beast::abstract_clock< + std::chrono::steady_clock>; + +/** A manual Stopwatch for unit tests. */ +using TestStopwatch = + beast::manual_clock< + std::chrono::steady_clock>; + /** Returns an instance of a wall clock. */ inline Stopwatch& diff --git a/src/ripple/basics/tests/KeyCache.test.cpp b/src/ripple/basics/tests/KeyCache.test.cpp index 8e86c6f8a..4da2dcdff 100644 --- a/src/ripple/basics/tests/KeyCache.test.cpp +++ b/src/ripple/basics/tests/KeyCache.test.cpp @@ -30,7 +30,7 @@ class KeyCache_test : public beast::unit_test::suite public: void run () { - TestClock clock; + TestStopwatch clock; clock.set (0); using Key = std::string; diff --git a/src/ripple/basics/tests/TaggedCache.test.cpp b/src/ripple/basics/tests/TaggedCache.test.cpp index 05dd61471..6bc5afda9 100644 --- a/src/ripple/basics/tests/TaggedCache.test.cpp +++ b/src/ripple/basics/tests/TaggedCache.test.cpp @@ -42,7 +42,7 @@ public: { beast::Journal const j; - TestClock clock; + TestStopwatch clock; clock.set (0); using Key = int; diff --git a/src/ripple/peerfinder/sim/Tests.cpp b/src/ripple/peerfinder/sim/Tests.cpp index 24a9645b8..2c624e3ac 100644 --- a/src/ripple/peerfinder/sim/Tests.cpp +++ b/src/ripple/peerfinder/sim/Tests.cpp @@ -65,7 +65,7 @@ private: Params m_params; Journal m_journal; int m_next_node_id; - TestClock m_clock; + TestNetClock m_clock; Peers m_nodes; Table m_table; FunctionQueue m_queue; diff --git a/src/ripple/peerfinder/tests/Livecache.test.cpp b/src/ripple/peerfinder/tests/Livecache.test.cpp index 9ebda4788..a2b088d8b 100644 --- a/src/ripple/peerfinder/tests/Livecache.test.cpp +++ b/src/ripple/peerfinder/tests/Livecache.test.cpp @@ -29,7 +29,7 @@ namespace PeerFinder { class Livecache_test : public beast::unit_test::suite { public: - TestClock m_clock; + TestStopwatch m_clock; // Add the address as an endpoint template diff --git a/src/ripple/peerfinder/tests/PeerFinder_test.cpp b/src/ripple/peerfinder/tests/PeerFinder_test.cpp index d14911330..b5750b94e 100644 --- a/src/ripple/peerfinder/tests/PeerFinder_test.cpp +++ b/src/ripple/peerfinder/tests/PeerFinder_test.cpp @@ -71,7 +71,7 @@ public: testcase("backoff 1"); TestStore store; TestChecker checker; - TestClock clock; + TestStopwatch clock; Logic logic (clock, store, checker, beast::Journal{}); logic.addFixedPeer ("test", beast::IP::Endpoint::from_string("65.0.0.1:5")); @@ -109,7 +109,7 @@ public: testcase("backoff 2"); TestStore store; TestChecker checker; - TestClock clock; + TestStopwatch clock; Logic logic (clock, store, checker, beast::Journal{}); logic.addFixedPeer ("test", beast::IP::Endpoint::from_string("65.0.0.1:5")); diff --git a/src/ripple/resource/impl/Logic.h b/src/ripple/resource/impl/Logic.h index 537a2a348..3d306bcd7 100644 --- a/src/ripple/resource/impl/Logic.h +++ b/src/ripple/resource/impl/Logic.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -37,7 +38,7 @@ namespace Resource { class Logic { private: - using clock_type = beast::abstract_clock ; + using clock_type = Stopwatch; using Imports = hash_map ; using Table = hash_map ; using EntryIntrusiveList = beast::List ; @@ -83,7 +84,7 @@ private: SharedState m_state; Stats m_stats; - beast::abstract_clock & m_clock; + Stopwatch& m_clock; beast::Journal m_journal; //-------------------------------------------------------------------------- diff --git a/src/ripple/resource/tests/Logic.test.cpp b/src/ripple/resource/tests/Logic.test.cpp index bd07b6f2b..15ea9b25e 100644 --- a/src/ripple/resource/tests/Logic.test.cpp +++ b/src/ripple/resource/tests/Logic.test.cpp @@ -31,13 +31,13 @@ class Manager_test : public beast::unit_test::suite { public: class TestLogic - : private boost::base_from_member + : private boost::base_from_member , public Logic { private: using clock_type = - boost::base_from_member; + boost::base_from_member; public: explicit TestLogic (beast::Journal journal) @@ -50,7 +50,7 @@ public: ++member; } - TestClock& clock () + TestStopwatch& clock () { return member; } diff --git a/src/ripple/shamap/tests/common.h b/src/ripple/shamap/tests/common.h index 8932706a1..f0211a30a 100644 --- a/src/ripple/shamap/tests/common.h +++ b/src/ripple/shamap/tests/common.h @@ -39,7 +39,7 @@ namespace tests { class TestFamily : public shamap::Family { private: - TestClock clock_; + TestStopwatch clock_; NodeStore::DummyScheduler scheduler_; TreeNodeCache treecache_; FullBelowCache fullbelow_; diff --git a/src/ripple/test/jtx/Env.h b/src/ripple/test/jtx/Env.h index 122a546e3..201827f64 100644 --- a/src/ripple/test/jtx/Env.h +++ b/src/ripple/test/jtx/Env.h @@ -117,7 +117,7 @@ noripple (Account const& account, class Env { public: - using clock_type = TestClock; + using clock_type = TestNetClock; clock_type clock; @@ -181,7 +181,7 @@ public: The Env clock is set to the new time. */ void - close (TestClock::time_point const& closeTime); + close (NetClock::time_point const& closeTime); /** Close and advance the ledger. @@ -193,6 +193,7 @@ public: close (std::chrono::duration< Rep, Period> const& elapsed) { + stopwatch_.advance(elapsed); close (clock.now() + elapsed); } @@ -443,6 +444,7 @@ public: protected: int trace_ = 0; bool testing_ = true; + TestStopwatch stopwatch_; void autofill_sig (JTx& jt); diff --git a/src/ripple/test/jtx/impl/Env.cpp b/src/ripple/test/jtx/impl/Env.cpp index c9b4d4532..3df2a83a8 100644 --- a/src/ripple/test/jtx/impl/Env.cpp +++ b/src/ripple/test/jtx/impl/Env.cpp @@ -58,7 +58,7 @@ Env::Env (beast::unit_test::suite& test_) generateSeed("masterpassphrase"))) , closed_ (std::make_shared( create_genesis, config)) - , cachedSLEs_ (std::chrono::seconds(5), clock) + , cachedSLEs_ (std::chrono::seconds(5), stopwatch_) , openLedger (closed_, config, cachedSLEs_, journal) { memoize(master); @@ -78,8 +78,7 @@ Env::closed() const } void -Env::close( - TestClock::time_point const& closeTime) +Env::close(NetClock::time_point const& closeTime) { clock.set(closeTime); // VFALCO TODO Fix the Ledger constructor @@ -111,10 +110,12 @@ Env::close( config, journal); accum.apply(*next); } - next->setAccepted( - closeTime.time_since_epoch().count(), - ledgerPossibleTimeResolutions[0], - true); + // To ensure that the close time is exact and not rounded, we don't + // claim to have reached consensus on what it should be. + next->setAccepted ( + std::chrono::duration_cast ( + closeTime.time_since_epoch ()).count (), + ledgerPossibleTimeResolutions[0], false); OrderedTxs locals({}); openLedger.accept(next, locals, false, retries, applyFlags(), *router);