(third_party deps) fix #177, update bundled spdlog to 1.6.0
This commit is contained in:
53
third_party/spdlog/tests/test_async.cpp
vendored
53
third_party/spdlog/tests/test_async.cpp
vendored
@ -5,14 +5,13 @@
|
||||
|
||||
TEST_CASE("basic async test ", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
size_t overrun_counter = 0;
|
||||
size_t queue_size = 128;
|
||||
size_t messages = 256;
|
||||
{
|
||||
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::block);
|
||||
for (size_t i = 0; i < messages; i++)
|
||||
{
|
||||
logger->info("Hello message #{}", i);
|
||||
@ -27,14 +26,13 @@ TEST_CASE("basic async test ", "[async]")
|
||||
|
||||
TEST_CASE("discard policy ", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
test_sink->set_delay(std::chrono::milliseconds(1));
|
||||
size_t queue_size = 4;
|
||||
size_t messages = 1024;
|
||||
|
||||
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::overrun_oldest);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::overrun_oldest);
|
||||
for (size_t i = 0; i < messages; i++)
|
||||
{
|
||||
logger->info("Hello message");
|
||||
@ -45,13 +43,12 @@ TEST_CASE("discard policy ", "[async]")
|
||||
|
||||
TEST_CASE("discard policy using factory ", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
size_t queue_size = 4;
|
||||
size_t messages = 1024;
|
||||
spdlog::init_thread_pool(queue_size, 1);
|
||||
|
||||
auto logger = spdlog::create_async_nb<sinks::test_sink_mt>("as2");
|
||||
auto test_sink = std::static_pointer_cast<sinks::test_sink_mt>(logger->sinks()[0]);
|
||||
auto logger = spdlog::create_async_nb<spdlog::sinks::test_sink_mt>("as2");
|
||||
auto test_sink = std::static_pointer_cast<spdlog::sinks::test_sink_mt>(logger->sinks()[0]);
|
||||
test_sink->set_delay(std::chrono::milliseconds(1));
|
||||
|
||||
for (size_t i = 0; i < messages; i++)
|
||||
@ -65,13 +62,12 @@ TEST_CASE("discard policy using factory ", "[async]")
|
||||
|
||||
TEST_CASE("flush", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
size_t queue_size = 256;
|
||||
size_t messages = 256;
|
||||
{
|
||||
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::block);
|
||||
for (size_t i = 0; i < messages; i++)
|
||||
{
|
||||
logger->info("Hello message #{}", i);
|
||||
@ -86,11 +82,9 @@ TEST_CASE("flush", "[async]")
|
||||
|
||||
TEST_CASE("async periodic flush", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
|
||||
auto logger = spdlog::create_async<sinks::test_sink_mt>("as");
|
||||
|
||||
auto test_sink = std::static_pointer_cast<sinks::test_sink_mt>(logger->sinks()[0]);
|
||||
auto logger = spdlog::create_async<spdlog::sinks::test_sink_mt>("as");
|
||||
auto test_sink = std::static_pointer_cast<spdlog::sinks::test_sink_mt>(logger->sinks()[0]);
|
||||
|
||||
spdlog::flush_every(std::chrono::seconds(1));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1100));
|
||||
@ -101,13 +95,12 @@ TEST_CASE("async periodic flush", "[async]")
|
||||
|
||||
TEST_CASE("tp->wait_empty() ", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
test_sink->set_delay(std::chrono::milliseconds(5));
|
||||
size_t messages = 100;
|
||||
|
||||
auto tp = std::make_shared<details::thread_pool>(messages, 2);
|
||||
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(messages, 2);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::block);
|
||||
for (size_t i = 0; i < messages; i++)
|
||||
{
|
||||
logger->info("Hello message #{}", i);
|
||||
@ -121,14 +114,13 @@ TEST_CASE("tp->wait_empty() ", "[async]")
|
||||
|
||||
TEST_CASE("multi threads", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
size_t queue_size = 128;
|
||||
size_t messages = 256;
|
||||
size_t n_threads = 10;
|
||||
{
|
||||
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::block);
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
for (size_t i = 0; i < n_threads; i++)
|
||||
@ -169,9 +161,10 @@ TEST_CASE("to_file", "[async]")
|
||||
}
|
||||
}
|
||||
|
||||
REQUIRE(count_lines(filename) == messages);
|
||||
require_message_count(filename, messages);
|
||||
auto contents = file_contents(filename);
|
||||
REQUIRE(ends_with(contents, std::string("Hello message #1023\n")));
|
||||
using spdlog::details::os::default_eol;
|
||||
REQUIRE(ends_with(contents, fmt::format("Hello message #1023{}", default_eol)));
|
||||
}
|
||||
|
||||
TEST_CASE("to_file multi-workers", "[async]")
|
||||
@ -191,5 +184,5 @@ TEST_CASE("to_file multi-workers", "[async]")
|
||||
}
|
||||
}
|
||||
|
||||
REQUIRE(count_lines(filename) == messages);
|
||||
require_message_count(filename, messages);
|
||||
}
|
||||
|
Reference in New Issue
Block a user