diff options
author | Alexey Salmin <alexey.salmin@gmail.com> | 2022-02-10 16:49:37 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:37 +0300 |
commit | 3c5b1607b38f637d2f3313791ed25c2e080d2647 (patch) | |
tree | 99be7b96e7c66612fbca94331100ef3b5fedcb88 /library/cpp/retry/retry_ut.cpp | |
parent | de89752358147d7b25ef59a85b431bb564068a49 (diff) | |
download | ydb-3c5b1607b38f637d2f3313791ed25c2e080d2647.tar.gz |
Restoring authorship annotation for Alexey Salmin <alexey.salmin@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/retry/retry_ut.cpp')
-rw-r--r-- | library/cpp/retry/retry_ut.cpp | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/library/cpp/retry/retry_ut.cpp b/library/cpp/retry/retry_ut.cpp index 92153e987e..f9eb58867b 100644 --- a/library/cpp/retry/retry_ut.cpp +++ b/library/cpp/retry/retry_ut.cpp @@ -1,36 +1,36 @@ -#include "retry.h" - +#include "retry.h" + #include <library/cpp/testing/unittest/registar.h> + +namespace { + class TDoOnSecondOrThrow { + public: + ui32 operator()() { + if (attempt++ != 1) { + throw yexception(); + } + return 42; + } -namespace { - class TDoOnSecondOrThrow { - public: - ui32 operator()() { - if (attempt++ != 1) { - throw yexception(); - } - return 42; - } - - private: - ui32 attempt = 0; - }; - - class TDoOnSecondOrFail { - public: - bool operator()() { - return (attempt++ == 1); - } - - private: - ui32 attempt = 0; - }; -} + private: + ui32 attempt = 0; + }; + + class TDoOnSecondOrFail { + public: + bool operator()() { + return (attempt++ == 1); + } + private: + ui32 attempt = 0; + }; +} + Y_UNIT_TEST_SUITE(Retry) { Y_UNIT_TEST(RetryOnExceptionSuccess) { - UNIT_ASSERT_NO_EXCEPTION(DoWithRetry(TDoOnSecondOrThrow{}, TRetryOptions(1, TDuration::Zero()))); - } + UNIT_ASSERT_NO_EXCEPTION(DoWithRetry(TDoOnSecondOrThrow{}, TRetryOptions(1, TDuration::Zero()))); + } Y_UNIT_TEST(RetryOnExceptionSuccessWithOnFail) { ui32 value = 0; std::function<void(const yexception&)> cb = [&value](const yexception&){ value += 1; }; @@ -38,19 +38,19 @@ Y_UNIT_TEST_SUITE(Retry) { UNIT_ASSERT_EQUAL(value, 1); } Y_UNIT_TEST(RetryOnExceptionFail) { - UNIT_ASSERT_EXCEPTION(DoWithRetry(TDoOnSecondOrThrow{}, TRetryOptions(0, TDuration::Zero())), yexception); - } + UNIT_ASSERT_EXCEPTION(DoWithRetry(TDoOnSecondOrThrow{}, TRetryOptions(0, TDuration::Zero())), yexception); + } Y_UNIT_TEST(RetryOnExceptionFailWithOnFail) { ui32 value = 0; std::function<void(const yexception&)> cb = [&value](const yexception&) { value += 1; }; UNIT_ASSERT_EXCEPTION(DoWithRetry<ui32>(TDoOnSecondOrThrow{}, cb, TRetryOptions(0, TDuration::Zero()), true), yexception); UNIT_ASSERT_EQUAL(value, 1); } - + Y_UNIT_TEST(RetryOnExceptionSuccessWithValue) { - std::function<ui32()> f = TDoOnSecondOrThrow{}; - UNIT_ASSERT(42 == *DoWithRetry<ui32>(f, TRetryOptions(1, TDuration::Zero()), false)); - } + std::function<ui32()> f = TDoOnSecondOrThrow{}; + UNIT_ASSERT(42 == *DoWithRetry<ui32>(f, TRetryOptions(1, TDuration::Zero()), false)); + } Y_UNIT_TEST(RetryOnExceptionSuccessWithValueWithOnFail) { ui32 value = 0; std::function<ui32()> f = TDoOnSecondOrThrow{}; @@ -59,9 +59,9 @@ Y_UNIT_TEST_SUITE(Retry) { UNIT_ASSERT_EQUAL(value, 1); } Y_UNIT_TEST(RetryOnExceptionFailWithValue) { - std::function<ui32()> f = TDoOnSecondOrThrow{}; - UNIT_ASSERT(!DoWithRetry<ui32>(f, TRetryOptions(0, TDuration::Zero()), false).Defined()); - } + std::function<ui32()> f = TDoOnSecondOrThrow{}; + UNIT_ASSERT(!DoWithRetry<ui32>(f, TRetryOptions(0, TDuration::Zero()), false).Defined()); + } Y_UNIT_TEST(RetryOnExceptionFailWithValueWithOnFail) { ui32 value = 0; std::function<ui32()> f = TDoOnSecondOrThrow{}; @@ -69,11 +69,11 @@ Y_UNIT_TEST_SUITE(Retry) { UNIT_ASSERT(!DoWithRetry<ui32>(f, cb, TRetryOptions(0, TDuration::Zero()), false).Defined()); UNIT_ASSERT_EQUAL(value, 1); } - + Y_UNIT_TEST(RetryOnExceptionSuccessWithValueAndRethrow) { - std::function<ui32()> f = TDoOnSecondOrThrow{}; - UNIT_ASSERT(42 == *DoWithRetry<ui32>(f, TRetryOptions(1, TDuration::Zero()), true)); - } + std::function<ui32()> f = TDoOnSecondOrThrow{}; + UNIT_ASSERT(42 == *DoWithRetry<ui32>(f, TRetryOptions(1, TDuration::Zero()), true)); + } Y_UNIT_TEST(RetryOnExceptionSuccessWithValueAndRethrowWithOnFail) { ui32 value = 0; std::function<ui32()> f = TDoOnSecondOrThrow{}; @@ -82,9 +82,9 @@ Y_UNIT_TEST_SUITE(Retry) { UNIT_ASSERT_EQUAL(value, 1); } Y_UNIT_TEST(RetryOnExceptionFailWithValueAndRethrow) { - std::function<ui32()> f = TDoOnSecondOrThrow{}; - UNIT_ASSERT_EXCEPTION(DoWithRetry<ui32>(f, TRetryOptions(0, TDuration::Zero()), true), yexception); - } + std::function<ui32()> f = TDoOnSecondOrThrow{}; + UNIT_ASSERT_EXCEPTION(DoWithRetry<ui32>(f, TRetryOptions(0, TDuration::Zero()), true), yexception); + } Y_UNIT_TEST(RetryOnExceptionFailWithValueAndRethrowWithOnFail) { ui32 value = 0; std::function<ui32()> f = TDoOnSecondOrThrow{}; @@ -92,13 +92,13 @@ Y_UNIT_TEST_SUITE(Retry) { UNIT_ASSERT_EXCEPTION(42 == *DoWithRetry<ui32>(f, cb, TRetryOptions(0, TDuration::Zero()), true), yexception); UNIT_ASSERT_EQUAL(value, 1); } - + Y_UNIT_TEST(RetryOnRetCodeSuccess) { - UNIT_ASSERT(true == DoWithRetryOnRetCode(TDoOnSecondOrFail{}, TRetryOptions(1, TDuration::Zero()))); - } + UNIT_ASSERT(true == DoWithRetryOnRetCode(TDoOnSecondOrFail{}, TRetryOptions(1, TDuration::Zero()))); + } Y_UNIT_TEST(RetryOnRetCodeFail) { - UNIT_ASSERT(false == DoWithRetryOnRetCode(TDoOnSecondOrFail{}, TRetryOptions(0, TDuration::Zero()))); - } + UNIT_ASSERT(false == DoWithRetryOnRetCode(TDoOnSecondOrFail{}, TRetryOptions(0, TDuration::Zero()))); + } Y_UNIT_TEST(MakeRetryOptionsFromProto) { NRetry::TRetryOptionsPB protoOptions; protoOptions.SetMaxTries(1); @@ -114,4 +114,4 @@ Y_UNIT_TEST_SUITE(Retry) { UNIT_ASSERT_EQUAL(options.SleepRandomDelta, TDuration::MilliSeconds(4)); UNIT_ASSERT_EQUAL(options.SleepExponentialMultiplier, TDuration::MilliSeconds(5)); } -} +} |