diff options
author | vvvv <[email protected]> | 2025-10-06 11:26:09 +0300 |
---|---|---|
committer | vvvv <[email protected]> | 2025-10-06 11:53:26 +0300 |
commit | 60f45e69a4d7dbc6131208e16c45faf35aa5a985 (patch) | |
tree | 4daa45b52c295a178c7620e4c93921465fcf7950 /yql/essentials/utils/retry_ut.cpp | |
parent | 1bded1a65a7e6e9171418f3e1c691d390125b64e (diff) |
YQL-20086 utils
init
commit_hash:54feccd520ebd0ab23612bc0cb830914dff9d0e8
Diffstat (limited to 'yql/essentials/utils/retry_ut.cpp')
-rw-r--r-- | yql/essentials/utils/retry_ut.cpp | 79 |
1 files changed, 37 insertions, 42 deletions
diff --git a/yql/essentials/utils/retry_ut.cpp b/yql/essentials/utils/retry_ut.cpp index 47cb35fd739..d3d42265180 100644 --- a/yql/essentials/utils/retry_ut.cpp +++ b/yql/essentials/utils/retry_ut.cpp @@ -6,68 +6,63 @@ using namespace NYql; namespace { -class TMyError : public yexception { +class TMyError: public yexception { }; -} +} // namespace Y_UNIT_TEST_SUITE(TRetryTests) { - Y_UNIT_TEST(ZeroAttempts) { - auto r = WithRetry<TMyError>(0, - []() { return TString("abc"); }, - [](auto, auto, auto) { UNIT_FAIL("Exception handler invoked"); }); +Y_UNIT_TEST(ZeroAttempts) { + auto r = WithRetry<TMyError>(0, + []() { return TString("abc"); }, + [](auto, auto, auto) { UNIT_FAIL("Exception handler invoked"); }); - UNIT_ASSERT_VALUES_EQUAL("abc", r); - } + UNIT_ASSERT_VALUES_EQUAL("abc", r); +} - Y_UNIT_TEST(NoRetries) { - auto r = WithRetry<TMyError>(5, - []() { return TString("abc"); }, - [](auto, auto, auto) { UNIT_FAIL("Exception handler invoked"); }); +Y_UNIT_TEST(NoRetries) { + auto r = WithRetry<TMyError>(5, + []() { return TString("abc"); }, + [](auto, auto, auto) { UNIT_FAIL("Exception handler invoked"); }); - UNIT_ASSERT_VALUES_EQUAL("abc", r); - } + UNIT_ASSERT_VALUES_EQUAL("abc", r); +} - Y_UNIT_TEST(NoRetriesButException) { - UNIT_ASSERT_EXCEPTION_CONTAINS(WithRetry<TMyError>(5, - []() { throw yexception() << "xxxx"; }, - [](auto, auto, auto) { UNIT_FAIL("Exception handler invoked"); }), yexception, "xxxx"); - } +Y_UNIT_TEST(NoRetriesButException) { + UNIT_ASSERT_EXCEPTION_CONTAINS(WithRetry<TMyError>(5, + []() { throw yexception() << "xxxx"; }, + [](auto, auto, auto) { UNIT_FAIL("Exception handler invoked"); }), yexception, "xxxx"); +} - Y_UNIT_TEST(FewRetries) { - int counter = 0; - int exceptions = 0; - auto r = WithRetry<TMyError>(3, [&]() { +Y_UNIT_TEST(FewRetries) { + int counter = 0; + int exceptions = 0; + auto r = WithRetry<TMyError>(3, [&]() { if (counter++ < 2) { throw TMyError() << "yyyy"; } - return counter; - }, [&](const auto& e, int attempt, int attemptCount) { + return counter; }, [&](const auto& e, int attempt, int attemptCount) { ++exceptions; UNIT_ASSERT_VALUES_EQUAL(e.what(), "yyyy"); UNIT_ASSERT_VALUES_EQUAL(attempt, counter); - UNIT_ASSERT_VALUES_EQUAL(attemptCount, 3); - }); + UNIT_ASSERT_VALUES_EQUAL(attemptCount, 3); }); - UNIT_ASSERT_VALUES_EQUAL(2, exceptions); - UNIT_ASSERT_VALUES_EQUAL(3, r); - UNIT_ASSERT_VALUES_EQUAL(3, counter); - } + UNIT_ASSERT_VALUES_EQUAL(2, exceptions); + UNIT_ASSERT_VALUES_EQUAL(3, r); + UNIT_ASSERT_VALUES_EQUAL(3, counter); +} - Y_UNIT_TEST(ManyRetries) { - int counter = 0; - int exceptions = 0; - UNIT_ASSERT_EXCEPTION_CONTAINS(WithRetry<TMyError>(3, [&]() { - throw TMyError() << "yyyy" << counter++; - }, [&](const auto& e, int attempt, int attemptCount) { +Y_UNIT_TEST(ManyRetries) { + int counter = 0; + int exceptions = 0; + UNIT_ASSERT_EXCEPTION_CONTAINS(WithRetry<TMyError>(3, [&]() { throw TMyError() << "yyyy" << counter++; }, [&](const auto& e, int attempt, int attemptCount) { ++exceptions; UNIT_ASSERT_STRING_CONTAINS(e.what(), "yyyy"); UNIT_ASSERT_VALUES_EQUAL(attempt, counter); - UNIT_ASSERT_VALUES_EQUAL(attemptCount, 3); - }), TMyError, "yyyy2"); + UNIT_ASSERT_VALUES_EQUAL(attemptCount, 3); }), TMyError, "yyyy2"); - UNIT_ASSERT_VALUES_EQUAL(2, exceptions); - UNIT_ASSERT_VALUES_EQUAL(3, counter); - } + UNIT_ASSERT_VALUES_EQUAL(2, exceptions); + UNIT_ASSERT_VALUES_EQUAL(3, counter); } +} // Y_UNIT_TEST_SUITE(TRetryTests) |