Isolate Application object in Env:

This change causes each instance of Env to construct its own
isolated Application object for testing. Also included is
part of a framework to create multiple Application objects
in the same unit test and connect them together.
This commit is contained in:
Vinnie Falco
2015-09-17 10:18:01 -07:00
parent 19903674af
commit 9315d98aa9
20 changed files with 630 additions and 368 deletions

View File

@@ -50,17 +50,41 @@ namespace test {
namespace jtx {
Env::AppBundle::AppBundle(Application* app_)
: app (app_)
{
}
Env::AppBundle::AppBundle(std::unique_ptr<Config const> config)
{
auto logs = std::make_unique<Logs>();
owned = make_Application(
std::move(config), std::move(logs));
app = owned.get();
}
//------------------------------------------------------------------------------
static
std::unique_ptr<Config const>
makeConfig()
{
auto p = std::make_unique<Config>();
setupConfigForUnitTests(*p);
return std::unique_ptr<Config const>(p.release());
}
// VFALCO Could wrap the log in a Journal here
Env::Env (beast::unit_test::suite& test_)
: test(test_)
, config()
, master("master", generateKeyPair(
: test (test_)
, master ("master", generateKeyPair(
KeyType::secp256k1,
generateSeed("masterpassphrase")))
, bundle_ (makeConfig())
, closed_ (std::make_shared<Ledger>(
create_genesis, config, app().family()))
create_genesis, app().config(), app().family()))
, cachedSLEs_ (std::chrono::seconds(5), stopwatch_)
, openLedger (closed_, config, cachedSLEs_, journal)
, openLedger (closed_, app().config(), cachedSLEs_, journal)
{
memoize(master);
initializePathfinding();
@@ -98,7 +122,7 @@ Env::close(NetClock::time_point const& closeTime)
OpenView accum(&*next);
OpenLedger::apply(app(), accum, *closed_,
txs, retries, applyFlags(), *router,
config, journal);
app().config(), journal);
accum.apply(*next);
}
// To ensure that the close time is exact and not rounded, we don't
@@ -254,7 +278,7 @@ Env::submit (JTx const& jt)
{
std::tie(ter_, didApply) = ripple::apply(
app(), view, *stx, applyFlags(),
directSigVerify, config,
directSigVerify, app().config(),
beast::Journal{});
return didApply;
});