mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-12 00:40:26 +08:00
Added tests for dup_filter sink
This commit is contained in:
parent
7f3b5fb84d
commit
98e151fda7
@ -14,7 +14,8 @@ set(SPDLOG_UTESTS_SOURCES
|
||||
test_mpmc_q.cpp
|
||||
test_sink.h
|
||||
test_fmt_helper.cpp
|
||||
test_stdout_api.cpp)
|
||||
test_stdout_api.cpp
|
||||
test_dup_filter.cpp)
|
||||
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")
|
||||
enable_testing()
|
||||
|
77
tests/test_dup_filter.cpp
Normal file
77
tests/test_dup_filter.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include "includes.h"
|
||||
#include "spdlog/sinks/dup_filter_sink.h"
|
||||
#include "test_sink.h"
|
||||
|
||||
using namespace spdlog;
|
||||
using namespace spdlog::sinks;
|
||||
|
||||
|
||||
TEST_CASE("dup_filter_test1", "[dup_filter_sink]")
|
||||
{
|
||||
dup_filter_sink_st dup_sink {std::chrono::seconds{5}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
}
|
||||
|
||||
REQUIRE(test_sink->msg_counter() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("dup_filter_test2", "[dup_filter_sink]")
|
||||
{
|
||||
dup_filter_sink_st dup_sink {std::chrono::seconds{0}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
}
|
||||
|
||||
REQUIRE(test_sink->msg_counter() == 10);
|
||||
}
|
||||
|
||||
TEST_CASE("dup_filter_test3", "[dup_filter_sink]")
|
||||
{
|
||||
dup_filter_sink_st dup_sink {std::chrono::seconds{0}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message2"});
|
||||
}
|
||||
|
||||
REQUIRE(test_sink->msg_counter() == 20);
|
||||
}
|
||||
|
||||
TEST_CASE("dup_filter_test4", "[dup_filter_sink]")
|
||||
{
|
||||
dup_filter_sink_st dup_sink {std::chrono::milliseconds{10}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message"});
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message"});
|
||||
REQUIRE(test_sink->msg_counter() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("dup_filter_test5", "[dup_filter_sink]")
|
||||
{
|
||||
dup_filter_sink_st dup_sink {std::chrono::seconds{5}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message2"});
|
||||
|
||||
REQUIRE(test_sink->msg_counter() == 3); // skip 2 messages but log the "skipped.." message before message2
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user