Skip to content

Commit

Permalink
Reduce console noise coming from unit tests:
Browse files Browse the repository at this point in the history
A few unit tests have historically generated a lot of noise
to the console from log writes.  This noise was not useful
and made it harder to locate actual test failures.

By changing the log level of these tests from
- severities::kError to
- severities::kDisabled
it was possible to remove that noise coming from the logs.
  • Loading branch information
scottschurr authored and nbougalis committed Jul 18, 2022
1 parent ee60b16 commit 0839a20
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 60 deletions.
39 changes: 27 additions & 12 deletions src/test/app/LedgerLoad_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
#include <ripple/beast/utility/temp_dir.h>
#include <ripple/protocol/SField.h>
#include <ripple/protocol/jss.h>
#include <test/jtx.h>
#include <test/jtx/Env.h>

#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <fstream>
#include <test/jtx.h>
#include <test/jtx/Env.h>

namespace ripple {

Expand Down Expand Up @@ -111,7 +112,9 @@ class LedgerLoad_test : public beast::unit_test::suite
Env env(
*this,
envconfig(
ledgerConfig, sd.dbPath, sd.ledgerFile, Config::LOAD_FILE));
ledgerConfig, sd.dbPath, sd.ledgerFile, Config::LOAD_FILE),
nullptr,
beast::severities::kDisabled);
auto jrb = env.rpc("ledger", "current", "full")[jss::result];
BEAST_EXPECT(
sd.ledger[jss::ledger][jss::accountState].size() ==
Expand All @@ -129,18 +132,19 @@ class LedgerLoad_test : public beast::unit_test::suite
except([&] {
Env env(
*this,
envconfig(ledgerConfig, sd.dbPath, "", Config::LOAD_FILE));
envconfig(ledgerConfig, sd.dbPath, "", Config::LOAD_FILE),
nullptr,
beast::severities::kDisabled);
});

// file does not exist
except([&] {
Env env(
*this,
envconfig(
ledgerConfig,
sd.dbPath,
"badfile.json",
Config::LOAD_FILE));
ledgerConfig, sd.dbPath, "badfile.json", Config::LOAD_FILE),
nullptr,
beast::severities::kDisabled);
});

// make a corrupted version of the ledger file (last 10 bytes removed).
Expand Down Expand Up @@ -168,7 +172,9 @@ class LedgerLoad_test : public beast::unit_test::suite
ledgerConfig,
sd.dbPath,
ledgerFileCorrupt.string(),
Config::LOAD_FILE));
Config::LOAD_FILE),
nullptr,
beast::severities::kDisabled);
});
}

Expand All @@ -183,7 +189,9 @@ class LedgerLoad_test : public beast::unit_test::suite
boost::erase_all(ledgerHash, "\"");
Env env(
*this,
envconfig(ledgerConfig, sd.dbPath, ledgerHash, Config::LOAD));
envconfig(ledgerConfig, sd.dbPath, ledgerHash, Config::LOAD),
nullptr,
beast::severities::kDisabled);
auto jrb = env.rpc("ledger", "current", "full")[jss::result];
BEAST_EXPECT(jrb[jss::ledger][jss::accountState].size() == 97);
BEAST_EXPECT(
Expand All @@ -199,7 +207,10 @@ class LedgerLoad_test : public beast::unit_test::suite

// create a new env with the ledger "latest" specified for startup
Env env(
*this, envconfig(ledgerConfig, sd.dbPath, "latest", Config::LOAD));
*this,
envconfig(ledgerConfig, sd.dbPath, "latest", Config::LOAD),
nullptr,
beast::severities::kDisabled);
auto jrb = env.rpc("ledger", "current", "full")[jss::result];
BEAST_EXPECT(
sd.ledger[jss::ledger][jss::accountState].size() ==
Expand All @@ -213,7 +224,11 @@ class LedgerLoad_test : public beast::unit_test::suite
using namespace test::jtx;

// create a new env with specific ledger index at startup
Env env(*this, envconfig(ledgerConfig, sd.dbPath, "43", Config::LOAD));
Env env(
*this,
envconfig(ledgerConfig, sd.dbPath, "43", Config::LOAD),
nullptr,
beast::severities::kDisabled);
auto jrb = env.rpc("ledger", "current", "full")[jss::result];
BEAST_EXPECT(
sd.ledger[jss::ledger][jss::accountState].size() ==
Expand Down
7 changes: 5 additions & 2 deletions src/test/app/LedgerReplay_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ struct LedgerServer
assert(param.initLedgers > 0);
createAccounts(param.initAccounts);
createLedgerHistory();
app.logs().threshold(beast::severities::Severity::kWarning);
app.logs().threshold(beast::severities::kWarning);
}

/**
Expand Down Expand Up @@ -567,7 +567,10 @@ class LedgerReplayClient
PeerSetBehavior behavior = PeerSetBehavior::Good,
InboundLedgersBehavior inboundBhvr = InboundLedgersBehavior::Good,
PeerFeature peerFeature = PeerFeature::LedgerReplayEnabled)
: env(suite, jtx::envconfig(jtx::port_increment, 3))
: env(suite,
jtx::envconfig(jtx::port_increment, 3),
nullptr,
beast::severities::kDisabled)
, app(env.app())
, ledgerMaster(env.app().getLedgerMaster())
, inboundLedgers(
Expand Down
7 changes: 6 additions & 1 deletion src/test/app/NFTokenDir_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,12 @@ class NFTokenDir_test : public beast::unit_test::suite
auto exerciseFixNFTokenDirV1 =
[this,
&features](std::initializer_list<std::string_view const> seeds) {
Env env{*this, features};
Env env{
*this,
envconfig(),
features,
nullptr,
beast::severities::kDisabled};

// Eventually all of the NFTokens will be owned by buyer.
Account const buyer{"buyer"};
Expand Down
12 changes: 10 additions & 2 deletions src/test/app/ValidatorKeys_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
#include <ripple/beast/unit_test.h>
#include <ripple/core/Config.h>
#include <ripple/core/ConfigSections.h>
#include <test/jtx/Env.h>

#include <string>
#include <test/unit_test/SuiteJournal.h>

namespace ripple {
namespace test {
Expand Down Expand Up @@ -75,7 +76,14 @@ class ValidatorKeys_test : public beast::unit_test::suite
void
run() override
{
SuiteJournal journal("ValidatorKeys_test", *this);
// We're only using Env for its Journal. That Journal gives better
// coverage in unit tests.
test::jtx::Env env{
*this,
test::jtx::envconfig(),
nullptr,
beast::severities::kDisabled};
beast::Journal journal{env.app().journal("ValidatorKeys_test")};

// Keys/ID when using [validation_seed]
SecretKey const seedSecretKey =
Expand Down
6 changes: 4 additions & 2 deletions src/test/app/ValidatorList_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
#include <ripple/protocol/digest.h>
#include <ripple/protocol/jss.h>
#include <ripple/protocol/messages.h>
#include <boost/beast/core/multi_buffer.hpp>
#include <test/jtx.h>

#include <boost/beast/core/multi_buffer.hpp>

namespace ripple {
namespace test {

Expand Down Expand Up @@ -217,7 +218,8 @@ class ValidatorList_test : public beast::unit_test::suite
{
testcase("Config Load");

jtx::Env env(*this);
jtx::Env env(
*this, jtx::envconfig(), nullptr, beast::severities::kDisabled);
auto& app = env.app();
PublicKey emptyLocalKey;
std::vector<std::string> const emptyCfgKeys;
Expand Down
8 changes: 1 addition & 7 deletions src/test/app/ValidatorSite_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ValidatorSite_test : public beast::unit_test::suite

using namespace jtx;

Env env(*this);
Env env(*this, envconfig(), nullptr, beast::severities::kDisabled);
auto trustedSites =
std::make_unique<ValidatorSite>(env.app(), env.journal);

Expand Down Expand Up @@ -282,9 +282,6 @@ class ValidatorSite_test : public beast::unit_test::suite
if (u.cfg.failFetch)
{
using namespace std::chrono;
log << " -- Msg: "
<< myStatus[jss::last_refresh_message].asString()
<< std::endl;
std::stringstream nextRefreshStr{
myStatus[jss::next_refresh_time].asString()};
system_clock::time_point nextRefresh;
Expand Down Expand Up @@ -357,9 +354,6 @@ class ValidatorSite_test : public beast::unit_test::suite
sink.messages().str().find(u.expectMsg) !=
std::string::npos,
sink.messages().str());
log << " -- Msg: "
<< myStatus[jss::last_refresh_message].asString()
<< std::endl;
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/test/basics/PerfLog_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
#include <ripple/json/json_reader.h>
#include <ripple/protocol/jss.h>
#include <ripple/rpc/impl/Handler.h>
#include <test/jtx/Env.h>

#include <atomic>
#include <chrono>
#include <cmath>
#include <random>
#include <string>
#include <test/jtx/Env.h>
#include <thread>

//------------------------------------------------------------------------------
Expand All @@ -44,7 +45,11 @@ class PerfLog_test : public beast::unit_test::suite

// We're only using Env for its Journal. That Journal gives better
// coverage in unit tests.
test::jtx::Env env_{*this};
test::jtx::Env env_{
*this,
test::jtx::envconfig(),
nullptr,
beast::severities::kDisabled};
beast::Journal j_{env_.app().journal("PerfLog_test")};

struct Fixture
Expand Down
3 changes: 0 additions & 3 deletions src/test/beast/beast_io_latency_probe_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,6 @@ class io_latency_probe_test : public beast::unit_test::suite,
duration_cast<milliseconds>(probe_duration).count()) /
static_cast<size_t>(tt.getMean<milliseconds>());
#endif
log << "expected_probe_count_min: " << expected_probe_count_min << "\n";
log << "expected_probe_count_max: " << expected_probe_count_max << "\n";

test_sampler io_probe{interval, get_io_service()};
io_probe.start();
MyTimer timer{get_io_service(), probe_duration};
Expand Down
14 changes: 10 additions & 4 deletions src/test/core/ClosureCounter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

#include <ripple/beast/unit_test.h>
#include <ripple/core/ClosureCounter.h>
#include <test/jtx/Env.h>

#include <atomic>
#include <chrono>
#include <test/jtx/Env.h>
#include <thread>

namespace ripple {
Expand All @@ -31,9 +32,14 @@ namespace test {

class ClosureCounter_test : public beast::unit_test::suite
{
// We're only using Env for its Journal.
jtx::Env env{*this};
beast::Journal j{env.app().journal("ClosureCounter_test")};
// We're only using Env for its Journal. That Journal gives better
// coverage in unit tests.
test::jtx::Env env_{
*this,
jtx::envconfig(),
nullptr,
beast::severities::kDisabled};
beast::Journal j{env_.app().journal("ClosureCounter_test")};

void
testConstruction()
Expand Down
5 changes: 1 addition & 4 deletions src/test/core/Config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class RippledCfgGuard : public ripple::test::detail::FileDirGuard
rmDataDir_ = !exists(dataDir_);
config_.setup(
file_.string(),
/*bQuiet*/ true,
/* bQuiet */ true,
/* bSilent */ false,
/* bStandalone */ false);
}
Expand Down Expand Up @@ -190,9 +190,6 @@ class RippledCfgGuard : public ripple::test::detail::FileDirGuard
using namespace boost::filesystem;
if (rmDataDir_)
rmDir(dataDir_);
else
test_.log << "Skipping rm dir: " << dataDir_.string()
<< std::endl;
}
catch (std::exception& e)
{
Expand Down
12 changes: 8 additions & 4 deletions src/test/jtx/Env_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,14 @@ class Env_test : public beast::unit_test::suite
testExceptionalShutdown()
{
except([this] {
jtx::Env env{*this, jtx::envconfig([](std::unique_ptr<Config> cfg) {
(*cfg).deprecatedClearSection("port_rpc");
return cfg;
})};
jtx::Env env{
*this,
jtx::envconfig([](std::unique_ptr<Config> cfg) {
(*cfg).deprecatedClearSection("port_rpc");
return cfg;
}),
nullptr,
beast::severities::kDisabled};
});
pass();
}
Expand Down
Loading

0 comments on commit 0839a20

Please sign in to comment.