From a73335579acbcc1a987ab258698af5a85965efc2 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 8 Jun 2020 09:07:49 -0400 Subject: [PATCH] silence logging in regression test --- llarp/ev/ev_libuv.cpp | 4 +- llarp/util/logging/logger.cpp | 10 ++++ llarp/util/logging/logger.hpp | 6 +- test/regress/2020-06-08-key-backup-bug.cpp | 70 +++++++++++++--------- 4 files changed, 59 insertions(+), 31 deletions(-) diff --git a/llarp/ev/ev_libuv.cpp b/llarp/ev/ev_libuv.cpp index 7242a71c8..0334b87cd 100644 --- a/llarp/ev/ev_libuv.cpp +++ b/llarp/ev/ev_libuv.cpp @@ -750,7 +750,9 @@ namespace libuv loop->process_timer_queue(); loop->process_cancel_queue(); loop->FlushLogic(); - llarp::LogContext::Instance().logStream->Tick(loop->time_now()); + auto& log = llarp::LogContext::Instance(); + if (log.logStream) + log.logStream->Tick(loop->time_now()); } Loop::Loop(size_t queue_size) diff --git a/llarp/util/logging/logger.cpp b/llarp/util/logging/logger.cpp index 64867b824..00daa34b3 100644 --- a/llarp/util/logging/logger.cpp +++ b/llarp/util/logging/logger.cpp @@ -174,6 +174,16 @@ namespace llarp } } + void + SilenceLog(std::function func) + { + auto& log = LogContext::Instance(); + ILogStream_ptr oldStream = std::move(log.logStream); + log.logStream = nullptr; + func(); + log.logStream = std::move(oldStream); + } + } // namespace llarp extern "C" diff --git a/llarp/util/logging/logger.hpp b/llarp/util/logging/logger.hpp index 20fb4d8f6..a01b54dbb 100644 --- a/llarp/util/logging/logger.hpp +++ b/llarp/util/logging/logger.hpp @@ -60,6 +60,10 @@ namespace llarp std::shared_ptr threadpool); }; + // call a function where the logging is slienced + void + SilenceLog(std::function func); + void SetLogLevel(LogLevel lvl); @@ -78,7 +82,7 @@ namespace llarp /* nop out logging for hive mode for now */ #ifndef LOKINET_HIVE auto& log = LogContext::Instance(); - if (log.curLevel > lvl) + if (log.curLevel > lvl || log.logStream == nullptr) return; std::stringstream ss; LogAppend(ss, std::forward(args)...); diff --git a/test/regress/2020-06-08-key-backup-bug.cpp b/test/regress/2020-06-08-key-backup-bug.cpp index a69281164..7763506be 100644 --- a/test/regress/2020-06-08-key-backup-bug.cpp +++ b/test/regress/2020-06-08-key-backup-bug.cpp @@ -5,14 +5,12 @@ #include #include -static const fs::path keyfilePath = "2020-06-08-key-backup-regression-test.private"; - static llarp_main* -make_context() +make_context(fs::path keyfile) { auto config = llarp_default_config(); config->impl.network.m_endpointType = "null"; - config->impl.network.m_keyfile = keyfilePath; + config->impl.network.m_keyfile = keyfile; config->impl.bootstrap.skipBootstrap = true; auto ptr = llarp_main_init_from_config(config, false); llarp_config_free(config); @@ -21,31 +19,45 @@ make_context() TEST_CASE("key backup bug regression test", "[regress]") { - llarp::service::Address endpointAddress{}; - for (size_t index = 0; index < 10; index++) - { - auto context = make_context(); - REQUIRE(llarp_main_setup(context, false) == 0); - auto ctx = llarp::Context::Get(context); - ctx->CallSafe([ctx, index, &endpointAddress]() { - auto ep = ctx->router->hiddenServiceContext().GetDefault(); - REQUIRE(ep != nullptr); - if (index == 0) - { - // first iteration, we are getting our identity - endpointAddress = ep->GetIdentity().pub.Addr(); - REQUIRE(not endpointAddress.IsZero()); - } - else + llarp::SilenceLog([]() { + for (const fs::path& path : {"regress-1.private", "regress-2.private", ""}) + { + llarp::service::Address endpointAddress{}; + for (size_t index = 0; index < 10; index++) { - REQUIRE(not endpointAddress.IsZero()); - // after the first iteration we expect the keys to stay the same - REQUIRE(endpointAddress == ep->GetIdentity().pub.Addr()); + auto context = make_context(path); + REQUIRE(llarp_main_setup(context, false) == 0); + auto ctx = llarp::Context::Get(context); + ctx->CallSafe([ctx, index, &endpointAddress, &path]() { + auto ep = ctx->router->hiddenServiceContext().GetDefault(); + REQUIRE(ep != nullptr); + if (index == 0) + { + REQUIRE(endpointAddress.IsZero()); + // first iteration, we are getting our identity + endpointAddress = ep->GetIdentity().pub.Addr(); + REQUIRE(not endpointAddress.IsZero()); + } + else + { + REQUIRE(not endpointAddress.IsZero()); + if (path.empty()) + { + // we want the keys to shift + REQUIRE(endpointAddress != ep->GetIdentity().pub.Addr()); + } + else + { + // after the first iteration we expect the keys to stay the same + REQUIRE(endpointAddress == ep->GetIdentity().pub.Addr()); + } + } + ctx->CloseAsync(); + }); + REQUIRE(llarp_main_run(context, llarp_main_runtime_opts{}) == 0); + llarp_main_free(context); } - ctx->CloseAsync(); - }); - REQUIRE(llarp_main_run(context, llarp_main_runtime_opts{}) == 0); - llarp_main_free(context); - } - fs::remove(keyfilePath); + fs::remove(path); + } + }); }