Skip to content

Commit 238a043

Browse files
committed
Additiona exponential backoff test for C++ 20
Signed-off-by: Simone Orru <simone.orru@secomind.com>
1 parent 52f4873 commit 238a043

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

unit/exponential_backoff_test.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,25 @@ TEST(AstarteTestExponentialBackoff, OrdinaryBackoff) {
4343
AllOf(Ge(std::chrono::minutes(17)), Le(std::chrono::minutes(19))));
4444
}
4545
}
46+
47+
TEST(AstarteTestExponentialBackoff, VeryLargeBackoff) {
48+
ExponentialBackoff backoff(
49+
std::chrono::hours(1),
50+
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::years(100)));
51+
EXPECT_THAT(backoff.getNextDelay(),
52+
AllOf(Ge(std::chrono::milliseconds::zero()), Le(std::chrono::hours(2))));
53+
EXPECT_THAT(backoff.getNextDelay(), AllOf(Ge(std::chrono::hours(1)), Le(std::chrono::hours(3))));
54+
EXPECT_THAT(backoff.getNextDelay(), AllOf(Ge(std::chrono::hours(3)), Le(std::chrono::hours(5))));
55+
EXPECT_THAT(backoff.getNextDelay(), AllOf(Ge(std::chrono::hours(7)), Le(std::chrono::hours(9))));
56+
// A lot of calls in between
57+
for (size_t i = 0; i < 1000000u; i++) {
58+
backoff.getNextDelay();
59+
}
60+
// Check it settled around the proper value
61+
for (size_t i = 0; i < 100u; i++) {
62+
EXPECT_THAT(
63+
backoff.getNextDelay(),
64+
AllOf(Ge(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::years(99))),
65+
Le(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::years(101)))));
66+
}
67+
}

0 commit comments

Comments
 (0)