diff options
author | Sergey Polovko <sergey@polovko.me> | 2022-02-10 16:47:03 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:03 +0300 |
commit | 2e714b5ebd40a1f4cc31c27f1ad6e49ca6d895f5 (patch) | |
tree | b83306b6e37edeea782e9eed673d89286c4fef35 /ydb/library/yql/utils/log/tls_backend_ut.cpp | |
parent | 3e0b762a82514bac89c1dd6ea7211e381d8aa248 (diff) | |
download | ydb-2e714b5ebd40a1f4cc31c27f1ad6e49ca6d895f5.tar.gz |
Restoring authorship annotation for Sergey Polovko <sergey@polovko.me>. Commit 2 of 2.
Diffstat (limited to 'ydb/library/yql/utils/log/tls_backend_ut.cpp')
-rw-r--r-- | ydb/library/yql/utils/log/tls_backend_ut.cpp | 220 |
1 files changed, 110 insertions, 110 deletions
diff --git a/ydb/library/yql/utils/log/tls_backend_ut.cpp b/ydb/library/yql/utils/log/tls_backend_ut.cpp index e55bc630cea..6f4147fed6b 100644 --- a/ydb/library/yql/utils/log/tls_backend_ut.cpp +++ b/ydb/library/yql/utils/log/tls_backend_ut.cpp @@ -1,121 +1,121 @@ -#include "tls_backend.h" -#include "log.h" +#include "tls_backend.h" +#include "log.h" #include <ydb/library/yql/utils/log/ut/log_parser.h> - + #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/logger/stream.h> #include <library/cpp/logger/null.h> - -#include <util/system/thread.h> -#include <util/string/split.h> - -#include <thread> -#include <chrono> - - -using namespace NYql; -using namespace NLog; - -class TRunnable { -public: - TRunnable(TStringBuf name, int count) - : Name_(name) - , Count_(count) - { - } - - void operator()() { - using namespace std::chrono_literals; - - YQL_LOG(INFO) << "this message will be missed"; - { - TScopedBackend<TStreamLogBackend> logBackend(&Logs_); - for (int i = 0; i < Count_; i++) { - YQL_LOG(INFO) << Name_; - std::this_thread::sleep_for(20ms); - } - } - YQL_LOG(INFO) << "this message will be missed"; - } - + +#include <util/system/thread.h> +#include <util/string/split.h> + +#include <thread> +#include <chrono> + + +using namespace NYql; +using namespace NLog; + +class TRunnable { +public: + TRunnable(TStringBuf name, int count) + : Name_(name) + , Count_(count) + { + } + + void operator()() { + using namespace std::chrono_literals; + + YQL_LOG(INFO) << "this message will be missed"; + { + TScopedBackend<TStreamLogBackend> logBackend(&Logs_); + for (int i = 0; i < Count_; i++) { + YQL_LOG(INFO) << Name_; + std::this_thread::sleep_for(20ms); + } + } + YQL_LOG(INFO) << "this message will be missed"; + } + const TString& GetLogs() const { - return Logs_.Str(); - } - -private: + return Logs_.Str(); + } + +private: TString Name_; - int Count_; - TStringStream Logs_; -}; - + int Count_; + TStringStream Logs_; +}; + Y_UNIT_TEST_SUITE(TTlsLogBackendTest) -{ +{ Y_UNIT_TEST(CaptureOutputs) { YqlLoggerScope logger(new TTlsLogBackend(new TNullLogBackend)); - - YQL_LOG(INFO) << "this message will be missed"; - - TRunnable r1("t1", 3); - std::thread t1(std::ref(r1)); - - TRunnable r2("t2", 2); - std::thread t2(std::ref(r2)); - - t1.join(); - t2.join(); - -// Cout << "--[t1 logs]-----------------\n" << r1.GetLogs() << Endl; -// Cout << "--[t2 logs]-----------------\n" << r2.GetLogs() << Endl; - - { // t1 + + YQL_LOG(INFO) << "this message will be missed"; + + TRunnable r1("t1", 3); + std::thread t1(std::ref(r1)); + + TRunnable r2("t2", 2); + std::thread t2(std::ref(r2)); + + t1.join(); + t2.join(); + +// Cout << "--[t1 logs]-----------------\n" << r1.GetLogs() << Endl; +// Cout << "--[t2 logs]-----------------\n" << r2.GetLogs() << Endl; + + { // t1 TString row1Str, row2Str, row3Str, _; - Split(r1.GetLogs(), '\n', row1Str, row2Str, row3Str, _); - - ui64 threadId = 0; - { - TLogRow logRow = ParseLogRow(row1Str); - UNIT_ASSERT_EQUAL(logRow.Level, ELevel::INFO); - UNIT_ASSERT_EQUAL(logRow.Component, EComponent::Default); - UNIT_ASSERT(logRow.ThreadId > 0); - UNIT_ASSERT_STRINGS_EQUAL(logRow.Message, "t1"); - threadId = logRow.ThreadId; - } - { - TLogRow logRow = ParseLogRow(row2Str); - UNIT_ASSERT_EQUAL(logRow.Level, ELevel::INFO); - UNIT_ASSERT_EQUAL(logRow.Component, EComponent::Default); - UNIT_ASSERT_EQUAL(logRow.ThreadId, threadId); - UNIT_ASSERT_STRINGS_EQUAL(logRow.Message, "t1"); - } - { - TLogRow logRow = ParseLogRow(row3Str); - UNIT_ASSERT_EQUAL(logRow.Level, ELevel::INFO); - UNIT_ASSERT_EQUAL(logRow.Component, EComponent::Default); - UNIT_ASSERT_EQUAL(logRow.ThreadId, threadId); - UNIT_ASSERT_STRINGS_EQUAL(logRow.Message, "t1"); - } - } - - { // t2 + Split(r1.GetLogs(), '\n', row1Str, row2Str, row3Str, _); + + ui64 threadId = 0; + { + TLogRow logRow = ParseLogRow(row1Str); + UNIT_ASSERT_EQUAL(logRow.Level, ELevel::INFO); + UNIT_ASSERT_EQUAL(logRow.Component, EComponent::Default); + UNIT_ASSERT(logRow.ThreadId > 0); + UNIT_ASSERT_STRINGS_EQUAL(logRow.Message, "t1"); + threadId = logRow.ThreadId; + } + { + TLogRow logRow = ParseLogRow(row2Str); + UNIT_ASSERT_EQUAL(logRow.Level, ELevel::INFO); + UNIT_ASSERT_EQUAL(logRow.Component, EComponent::Default); + UNIT_ASSERT_EQUAL(logRow.ThreadId, threadId); + UNIT_ASSERT_STRINGS_EQUAL(logRow.Message, "t1"); + } + { + TLogRow logRow = ParseLogRow(row3Str); + UNIT_ASSERT_EQUAL(logRow.Level, ELevel::INFO); + UNIT_ASSERT_EQUAL(logRow.Component, EComponent::Default); + UNIT_ASSERT_EQUAL(logRow.ThreadId, threadId); + UNIT_ASSERT_STRINGS_EQUAL(logRow.Message, "t1"); + } + } + + { // t2 TString row1Str, row2Str, _; - Split(r2.GetLogs(), '\n', row1Str, row2Str, _); - - ui64 threadId = 0; - { - TLogRow logRow = ParseLogRow(row1Str); - UNIT_ASSERT_EQUAL(logRow.Level, ELevel::INFO); - UNIT_ASSERT_EQUAL(logRow.Component, EComponent::Default); - UNIT_ASSERT(logRow.ThreadId > 0); - UNIT_ASSERT_STRINGS_EQUAL(logRow.Message, "t2"); - threadId = logRow.ThreadId; - } - { - TLogRow logRow = ParseLogRow(row2Str); - UNIT_ASSERT_EQUAL(logRow.Level, ELevel::INFO); - UNIT_ASSERT_EQUAL(logRow.Component, EComponent::Default); - UNIT_ASSERT_EQUAL(logRow.ThreadId, threadId); - UNIT_ASSERT_STRINGS_EQUAL(logRow.Message, "t2"); - } - } - } -} + Split(r2.GetLogs(), '\n', row1Str, row2Str, _); + + ui64 threadId = 0; + { + TLogRow logRow = ParseLogRow(row1Str); + UNIT_ASSERT_EQUAL(logRow.Level, ELevel::INFO); + UNIT_ASSERT_EQUAL(logRow.Component, EComponent::Default); + UNIT_ASSERT(logRow.ThreadId > 0); + UNIT_ASSERT_STRINGS_EQUAL(logRow.Message, "t2"); + threadId = logRow.ThreadId; + } + { + TLogRow logRow = ParseLogRow(row2Str); + UNIT_ASSERT_EQUAL(logRow.Level, ELevel::INFO); + UNIT_ASSERT_EQUAL(logRow.Component, EComponent::Default); + UNIT_ASSERT_EQUAL(logRow.ThreadId, threadId); + UNIT_ASSERT_STRINGS_EQUAL(logRow.Message, "t2"); + } + } + } +} |