From 530e209f660bb2ba96541111ab9eec0987f4a35d Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 14 Aug 2018 00:58:50 +0300 Subject: [PATCH] Fixed async tests to pass TASN checks --- tests/test_async.cpp | 16 ++++++++++------ tests/test_sink.h | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/test_async.cpp b/tests/test_async.cpp index 112fede7..c4324df4 100644 --- a/tests/test_async.cpp +++ b/tests/test_async.cpp @@ -26,8 +26,9 @@ TEST_CASE("discard policy ", "[async]") { using namespace spdlog; auto test_sink = std::make_shared(); - 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(queue_size, 1); auto logger = std::make_shared("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("as2"); + auto test_sink = std::static_pointer_cast(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(logger->sinks()[0]); - REQUIRE(sink->msg_counter() < messages); + + REQUIRE(test_sink->msg_counter() < messages); spdlog::drop_all(); } diff --git a/tests/test_sink.h b/tests/test_sink.h index 101c15f1..ae08e980 100644 --- a/tests/test_sink.h +++ b/tests/test_sink.h @@ -21,11 +21,13 @@ class test_sink : public base_sink public: size_t msg_counter() { + std::lock_guard lock(base_sink::mutex_); return msg_counter_; } size_t flush_counter() { + std::lock_guard lock(base_sink::mutex_); return flush_counter_; }