mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-24 09:31:34 +08:00
Fixed async tests to pass TASN checks
This commit is contained in:
parent
566df7e826
commit
530e209f66
@ -26,8 +26,9 @@ TEST_CASE("discard policy ", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
size_t queue_size = 2;
|
||||
size_t messages = 10240;
|
||||
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);
|
||||
@ -41,17 +42,20 @@ TEST_CASE("discard policy ", "[async]")
|
||||
TEST_CASE("discard policy using factory ", "[async]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
size_t queue_size = 2;
|
||||
size_t messages = 10240;
|
||||
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]);
|
||||
test_sink->set_delay(std::chrono::milliseconds(1));
|
||||
|
||||
for (size_t i = 0; i < messages; i++)
|
||||
{
|
||||
logger->info("Hello message");
|
||||
}
|
||||
auto sink = std::static_pointer_cast<sinks::test_sink_mt>(logger->sinks()[0]);
|
||||
REQUIRE(sink->msg_counter() < messages);
|
||||
|
||||
REQUIRE(test_sink->msg_counter() < messages);
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
|
@ -21,11 +21,13 @@ class test_sink : public base_sink<Mutex>
|
||||
public:
|
||||
size_t msg_counter()
|
||||
{
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||
return msg_counter_;
|
||||
}
|
||||
|
||||
size_t flush_counter()
|
||||
{
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||
return flush_counter_;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user