silence logging in regression test

pull/1301/head
Jeff Becker 4 years ago
parent 800668348a
commit a73335579a
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -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)

@ -174,6 +174,16 @@ namespace llarp
}
}
void
SilenceLog(std::function<void(void)> 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"

@ -60,6 +60,10 @@ namespace llarp
std::shared_ptr<thread::ThreadPool> threadpool);
};
// call a function where the logging is slienced
void
SilenceLog(std::function<void(void)> 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<TArgs>(args)...);

@ -5,14 +5,12 @@
#include <service/context.hpp>
#include <catch2/catch.hpp>
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);
@ -20,18 +18,22 @@ make_context()
}
TEST_CASE("key backup bug regression test", "[regress]")
{
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++)
{
auto context = make_context();
auto context = make_context(path);
REQUIRE(llarp_main_setup(context, false) == 0);
auto ctx = llarp::Context::Get(context);
ctx->CallSafe([ctx, index, &endpointAddress]() {
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());
@ -39,13 +41,23 @@ TEST_CASE("key backup bug regression test", "[regress]")
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);
}
fs::remove(keyfilePath);
fs::remove(path);
}
});
}

Loading…
Cancel
Save