From 1cbb079ecb3328b501da4e4bdb362ef2b91ad2bb Mon Sep 17 00:00:00 2001 From: jon2205 Date: Thu, 10 Feb 2022 16:50:59 +0300 Subject: Restoring authorship annotation for . Commit 1 of 2. --- library/cpp/monlib/counters/timer.h | 2 +- library/cpp/monlib/counters/timer_ut.cpp | 48 ++++++++++++++++---------------- 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'library/cpp/monlib/counters') diff --git a/library/cpp/monlib/counters/timer.h b/library/cpp/monlib/counters/timer.h index 03dfb35337f..d64606b2a08 100644 --- a/library/cpp/monlib/counters/timer.h +++ b/library/cpp/monlib/counters/timer.h @@ -166,7 +166,7 @@ namespace NMonitoring { (*Callback_)(duration); } Timer_->RecordValue(duration); - } + } private: TTimer* Timer_; diff --git a/library/cpp/monlib/counters/timer_ut.cpp b/library/cpp/monlib/counters/timer_ut.cpp index c5cd07e89d5..207006fc3af 100644 --- a/library/cpp/monlib/counters/timer_ut.cpp +++ b/library/cpp/monlib/counters/timer_ut.cpp @@ -5,17 +5,17 @@ using namespace NMonitoring; using namespace std::literals::chrono_literals; -class TCallback { -public: +class TCallback { +public: explicit TCallback(int value) : Value_(value){}; - void operator()(std::chrono::high_resolution_clock::duration duration) { - Value_ = duration.count(); - }; - - int Value_; -}; - + void operator()(std::chrono::high_resolution_clock::duration duration) { + Value_ = duration.count(); + }; + + int Value_; +}; + Y_UNIT_TEST_SUITE(TTimerTest) { Y_UNIT_TEST(RecordValue) { TTimerNs timerNs(1ns, 1s); @@ -62,20 +62,20 @@ Y_UNIT_TEST_SUITE(TTimerTest) { UNIT_ASSERT(snapshot.Max > std::chrono::microseconds(10ms).count()); UNIT_ASSERT_DOUBLES_EQUAL(snapshot.StdDeviation, 0.0, 1e-6); } - + Y_UNIT_TEST(TimerScopeWithCallback) { - TCallback callback(0); - TTimerUs timer(1us, 1000s); - { - TTimerScope scope(&timer, &callback); - Sleep(TDuration::MilliSeconds(10)); - } - THistogramSnapshot snapshot; - timer.TakeSnapshot(&snapshot); - - UNIT_ASSERT(snapshot.Min > std::chrono::microseconds(10ms).count()); - UNIT_ASSERT(snapshot.Max > std::chrono::microseconds(10ms).count()); - UNIT_ASSERT_DOUBLES_EQUAL(snapshot.StdDeviation, 0.0, 1e-6); - UNIT_ASSERT(callback.Value_ > std::chrono::microseconds(10ms).count()); - } + TCallback callback(0); + TTimerUs timer(1us, 1000s); + { + TTimerScope scope(&timer, &callback); + Sleep(TDuration::MilliSeconds(10)); + } + THistogramSnapshot snapshot; + timer.TakeSnapshot(&snapshot); + + UNIT_ASSERT(snapshot.Min > std::chrono::microseconds(10ms).count()); + UNIT_ASSERT(snapshot.Max > std::chrono::microseconds(10ms).count()); + UNIT_ASSERT_DOUBLES_EQUAL(snapshot.StdDeviation, 0.0, 1e-6); + UNIT_ASSERT(callback.Value_ > std::chrono::microseconds(10ms).count()); + } } -- cgit v1.3