aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/tvmauth/client/ut/exponential_backoff_ut.cpp
diff options
context:
space:
mode:
authorkomels <komels@yandex-team.ru>2022-04-14 13:10:53 +0300
committerkomels <komels@yandex-team.ru>2022-04-14 13:10:53 +0300
commit21c9b0e6b039e9765eb414c406c2b86e8cea6850 (patch)
treef40ebc18ff8958dfbd189954ad024043ca983ea5 /library/cpp/tvmauth/client/ut/exponential_backoff_ut.cpp
parent9a4effa852abe489707139c2b260dccc6f4f9aa9 (diff)
downloadydb-21c9b0e6b039e9765eb414c406c2b86e8cea6850.tar.gz
Final part on compatibility layer: LOGBROKER-7215
ref:777c67aadbf705d19034a09a792b2df61ba53697
Diffstat (limited to 'library/cpp/tvmauth/client/ut/exponential_backoff_ut.cpp')
-rw-r--r--library/cpp/tvmauth/client/ut/exponential_backoff_ut.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/library/cpp/tvmauth/client/ut/exponential_backoff_ut.cpp b/library/cpp/tvmauth/client/ut/exponential_backoff_ut.cpp
new file mode 100644
index 0000000000..3dcbe6ad49
--- /dev/null
+++ b/library/cpp/tvmauth/client/ut/exponential_backoff_ut.cpp
@@ -0,0 +1,44 @@
+#include <library/cpp/tvmauth/client/misc/exponential_backoff.h>
+
+#include <library/cpp/testing/unittest/registar.h>
+
+#include <thread>
+
+using namespace NTvmAuth;
+
+Y_UNIT_TEST_SUITE(PasspUtilsExpBackoff) {
+ Y_UNIT_TEST(common) {
+ TExponentialBackoff b({TDuration::Seconds(1), TDuration::Seconds(60), 2, 0.01});
+
+ UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(1), b.GetCurrentValue());
+
+ TDuration dur = b.GetCurrentValue();
+ for (size_t idx = 0; idx < 6; ++idx) {
+ TDuration newValue = b.Increase();
+ UNIT_ASSERT_LT(dur, newValue);
+ dur = newValue;
+ }
+
+ UNIT_ASSERT_LT(TDuration::Seconds(60) - TDuration::Seconds(3), dur);
+ UNIT_ASSERT_LT(dur, TDuration::Seconds(60) + TDuration::Seconds(3));
+ }
+
+ Y_UNIT_TEST(sleep) {
+ TExponentialBackoff b({TDuration::Seconds(60), TDuration::Seconds(600), 2, 0.01});
+
+ const TInstant start = TInstant::Now();
+
+ TAutoEvent started;
+ std::thread t([&b, &started]() {
+ started.Signal();
+ b.Sleep();
+ });
+
+ started.WaitT(TDuration::Seconds(30));
+ b.Interrupt();
+ t.join();
+ TDuration dur = TInstant::Now() - start;
+
+ UNIT_ASSERT_LT(dur, TDuration::Seconds(60));
+ }
+}