From 49bcdda41881f6cac140879a236be6ac1a7a734d Mon Sep 17 00:00:00 2001 From: Mike Ellery Date: Tue, 19 Jun 2018 18:00:16 -0700 Subject: [PATCH] Improve charge handling in NoRippleCheckLimits test (RIPD-1641) --- src/test/rpc/NoRippleCheck_test.cpp | 45 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/test/rpc/NoRippleCheck_test.cpp b/src/test/rpc/NoRippleCheck_test.cpp index a630a4bf1c..db2773d782 100644 --- a/src/test/rpc/NoRippleCheck_test.cpp +++ b/src/test/rpc/NoRippleCheck_test.cpp @@ -254,27 +254,36 @@ class NoRippleCheckLimits_test : public beast::unit_test::suite env (fset (alice, asfDefaultRipple)); env.close (); + auto checkBalance = [&env]() + { + // this is endpoint drop prevention. Non admin ports will drop + // requests if they are coming too fast, so we manipulate the + // resource manager here to reset the enpoint balance (for + // localhost) if we get too close to the drop limit. It would + // be better if we could add this functionality to Env somehow + // or otherwise disable endpoint charging for certain test + // cases. + using namespace ripple::Resource; + using namespace std::chrono; + using namespace beast::IP; + auto c = env.app ().getResourceManager () + .newInboundEndpoint ( + Endpoint::from_string (test::getEnvLocalhostAddr())); + + // if we go above the warning threshold, reset + if (c.balance() > warningThreshold) + { + using clock_type = beast::abstract_clock ; + c.entry().local_balance = + DecayingSample + {steady_clock::now()}; + } + }; + for (auto i = 0; i < ripple::RPC::Tuning::noRippleCheck.rmax + 5; ++i) { if (! admin) - { - // endpoint drop prevention. Non admin ports will drop requests - // if they are coming too fast, so we manipulate the resource - // manager here to reset the enpoint balance (for localhost) if - // we get too close to the drop limit. - using namespace ripple::Resource; - using namespace std::chrono; - using namespace beast::IP; - auto c = env.app().getResourceManager() - .newInboundEndpoint (Endpoint::from_string (test::getEnvLocalhostAddr())); - if (dropThreshold - c.balance() <= 20) - { - using clock_type = beast::abstract_clock ; - c.entry().local_balance = - DecayingSample - {steady_clock::now()}; - } - } + checkBalance(); auto& txq = env.app().getTxQ(); auto const gw = Account {"gw" + std::to_string(i)};