Skip to content

Commit

Permalink
fix: respond to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alevenberg committed May 24, 2023
1 parent b8cf698 commit f41e756
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions google/cloud/internal/backoff_policy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using ::testing::Not;

/// @test A simple test for the ExponentialBackoffPolicy.
TEST(ExponentialBackoffPolicy, Simple) {
ExponentialBackoffPolicy tested(ms(10), ms(80), 2.0);
ExponentialBackoffPolicy tested(ms(10), ms(100), 2.0);

auto delay = tested.OnCompletion();
EXPECT_LE(ms(10), delay);
Expand All @@ -36,7 +36,7 @@ TEST(ExponentialBackoffPolicy, Simple) {
EXPECT_GE(ms(40), delay);
delay = tested.OnCompletion();
EXPECT_LE(ms(10), delay);
EXPECT_GE(ms(80), delay);
EXPECT_GE(ms(100), delay);
}

/// @test Verify a full jitter policy, where the minimum delay is set to 0.
Expand All @@ -61,6 +61,24 @@ TEST(ExponentialBackoffPolicy, VerifyFullJitterPolicy) {
TEST(ExponentialBackoffPolicy, VerifyFullJitterPolicy) {
ExponentialBackoffPolicy tested(ms(0), ms(10), ms(50), 2.0);

auto delay = tested.OnCompletion();
EXPECT_LE(ms(0), delay);
EXPECT_GE(ms(10), delay);
delay = tested.OnCompletion();
EXPECT_LE(ms(0), delay);
EXPECT_GE(ms(20), delay);
delay = tested.OnCompletion();
EXPECT_LE(ms(0), delay);
EXPECT_GE(ms(40), delay);
delay = tested.OnCompletion();
EXPECT_LE(ms(10), delay);
EXPECT_GE(ms(100), delay);
}

/// @test Verify a full jitter policy, where the minimum delay is set to 0.
TEST(ExponentialBackoffPolicy, VerifyFullJitterPolicy) {
ExponentialBackoffPolicy tested(ms(10), ms(0), ms(50), 2.0);

auto delay = tested.OnCompletion();
EXPECT_LE(ms(0), delay);
EXPECT_GE(ms(10), delay);
Expand Down Expand Up @@ -93,13 +111,7 @@ TEST(ExponentialBackoffPolicy, DetermineRangeUsingScalingFactor) {

auto delay = tested.OnCompletion();
EXPECT_LE(ms(1000), delay);
EXPECT_GE(ms(2000), delay);
delay = tested.OnCompletion();
EXPECT_LE(ms(1000), delay);
EXPECT_GE(ms(2001), delay);
delay = tested.OnCompletion();
EXPECT_LE(ms(1000), delay);
EXPECT_GE(ms(2002), delay);
EXPECT_GE(ms(1001), delay);
}

/// @test Verify that the scaling factor is validated.
Expand Down Expand Up @@ -135,7 +147,7 @@ TEST(ExponentialBackoffPolicy, DifferentParameters) {

auto delay = tested.OnCompletion();
EXPECT_LE(ms(100), delay) << "delay=" << delay.count() << "ms";
EXPECT_GE(ms(200), delay) << "delay=" << delay.count() << "ms";
EXPECT_GE(ms(150), delay) << "delay=" << delay.count() << "ms";
delay = tested.OnCompletion();
EXPECT_LE(ms(100), delay) << "delay=" << delay.count() << "ms";
EXPECT_GE(ms(225), delay) << "delay=" << delay.count() << "ms";
Expand Down

0 comments on commit f41e756

Please sign in to comment.