diff options
author | dima-zakharov <dima-zakharov@yandex-team.ru> | 2022-02-10 16:46:02 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:02 +0300 |
commit | 41e8c41790ddd8d92722a09f7d4e1934aefff0c5 (patch) | |
tree | 2f175d77fb38a4093ccc33353129ccff1e7db7ce /library/cpp/logger/log_ut.cpp | |
parent | ed935c8a4c7e6ca561c19047402b0f7442175b51 (diff) | |
download | ydb-41e8c41790ddd8d92722a09f7d4e1934aefff0c5.tar.gz |
Restoring authorship annotation for <dima-zakharov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/logger/log_ut.cpp')
-rw-r--r-- | library/cpp/logger/log_ut.cpp | 110 |
1 files changed, 55 insertions, 55 deletions
diff --git a/library/cpp/logger/log_ut.cpp b/library/cpp/logger/log_ut.cpp index 8de46f17f5..c5fd158c85 100644 --- a/library/cpp/logger/log_ut.cpp +++ b/library/cpp/logger/log_ut.cpp @@ -3,8 +3,8 @@ #include <library/cpp/testing/unittest/registar.h> #include <util/system/fs.h> -#include <util/system/rwlock.h> -#include <util/system/yield.h> +#include <util/system/rwlock.h> +#include <util/system/yield.h> #include <util/memory/blob.h> #include <util/stream/file.h> #include <util/generic/string.h> @@ -16,7 +16,7 @@ class TLogTest: public TTestBase { UNIT_TEST(TestFormat) UNIT_TEST(TestWrite) UNIT_TEST(TestThreaded) - UNIT_TEST(TestThreadedWithOverflow) + UNIT_TEST(TestThreadedWithOverflow) UNIT_TEST(TestNoFlush) UNIT_TEST_SUITE_END(); @@ -25,7 +25,7 @@ private: void TestFormat(); void TestWrite(); void TestThreaded(); - void TestThreadedWithOverflow(); + void TestThreadedWithOverflow(); void TestNoFlush(); void SetUp() override; void TearDown() override; @@ -78,59 +78,59 @@ void TLogTest::TestThreaded() { UNIT_ASSERT_EQUAL(TString((const char*)data.Begin(), data.Size()), "some useful data 12, 34, 3.000000, qwqwqw\n"); } -void TLogTest::TestThreadedWithOverflow() { - class TFakeLogBackend: public TLogBackend { - public: - TWriteGuard Guard() { - return TWriteGuard(Lock_); - } - - void WriteData(const TLogRecord&) override { - TReadGuard guard(Lock_); - } - - void ReopenLog() override { - TWriteGuard guard(Lock_); - } - - private: - TRWMutex Lock_; - }; - - auto waitForFreeQueue = [](const TLog& log) { - ThreadYield(); - while (log.BackEndQueueSize() > 0) { - Sleep(TDuration::MilliSeconds(1)); - } - }; - - TFakeLogBackend fb; - { +void TLogTest::TestThreadedWithOverflow() { + class TFakeLogBackend: public TLogBackend { + public: + TWriteGuard Guard() { + return TWriteGuard(Lock_); + } + + void WriteData(const TLogRecord&) override { + TReadGuard guard(Lock_); + } + + void ReopenLog() override { + TWriteGuard guard(Lock_); + } + + private: + TRWMutex Lock_; + }; + + auto waitForFreeQueue = [](const TLog& log) { + ThreadYield(); + while (log.BackEndQueueSize() > 0) { + Sleep(TDuration::MilliSeconds(1)); + } + }; + + TFakeLogBackend fb; + { TLog log(THolder(new TThreadedLogBackend(&fb, 2))); - - auto guard = fb.Guard(); - log.AddLog("first write"); - waitForFreeQueue(log); - log.AddLog("second write (first in queue)"); - log.AddLog("third write (second in queue)"); - UNIT_ASSERT_EXCEPTION(log.AddLog("fourth write (queue overflow)"), yexception); - } - - { - ui32 overflows = 0; + + auto guard = fb.Guard(); + log.AddLog("first write"); + waitForFreeQueue(log); + log.AddLog("second write (first in queue)"); + log.AddLog("third write (second in queue)"); + UNIT_ASSERT_EXCEPTION(log.AddLog("fourth write (queue overflow)"), yexception); + } + + { + ui32 overflows = 0; TLog log(THolder(new TThreadedLogBackend(&fb, 2, [&overflows] { ++overflows; }))); - - auto guard = fb.Guard(); - log.AddLog("first write"); - waitForFreeQueue(log); - log.AddLog("second write (first in queue)"); - log.AddLog("third write (second in queue)"); - UNIT_ASSERT_EQUAL(overflows, 0); - log.AddLog("fourth write (queue overflow)"); - UNIT_ASSERT_EQUAL(overflows, 1); - } -} - + + auto guard = fb.Guard(); + log.AddLog("first write"); + waitForFreeQueue(log); + log.AddLog("second write (first in queue)"); + log.AddLog("third write (second in queue)"); + UNIT_ASSERT_EQUAL(overflows, 0); + log.AddLog("fourth write (queue overflow)"); + UNIT_ASSERT_EQUAL(overflows, 1); + } +} + void TLogTest::TestNoFlush() { { TFileLogBackend fb(LOGFILE); |