Skip to content

Commit

Permalink
chore: after a day of retrying, start with a 1 hour delay instead of …
Browse files Browse the repository at this point in the history
…dependent on retry cause (#675)
  • Loading branch information
richardapeters authored Jul 12, 2024
1 parent 63c55e0 commit 386af63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion infra/timer/RetryPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace infra
if (infra::Now() >= retryAfterMaximumDelay)
{
retryAfterMaximumDelay += maximumDelay;
*retryDelay = InitialDelay(intermittentFailure);
*retryDelay = InitialDelay(false);
}
else
{
Expand Down
20 changes: 10 additions & 10 deletions infra/timer/test/TestRetryPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class RetryPolicyTest
TEST_F(RetryPolicyTest, should_return_retry_delay_after_intermittent_failure)
{
infra::RetryPolicyExponentialBackoff policy;
ASSERT_EQ(std::chrono::minutes(1), policy.RetryDelay(true));
EXPECT_EQ(std::chrono::minutes(1), policy.RetryDelay(true));
}

TEST_F(RetryPolicyTest, should_return_retry_delay_after_non_intermittent_failure)
{
infra::RetryPolicyExponentialBackoff policy;
ASSERT_EQ(std::chrono::hours(1), policy.RetryDelay(false));
EXPECT_EQ(std::chrono::hours(1), policy.RetryDelay(false));
}

TEST_F(RetryPolicyTest, should_return_exponentially_larger_delay)
Expand All @@ -26,7 +26,7 @@ TEST_F(RetryPolicyTest, should_return_exponentially_larger_delay)
infra::Duration initialDelay = std::chrono::minutes(1);

for (int i = 0; i < 10; ++i)
ASSERT_EQ(std::pow(2, i) * initialDelay, policy.RetryDelay(true));
EXPECT_EQ(std::pow(2, i) * initialDelay, policy.RetryDelay(true));
}

TEST_F(RetryPolicyTest, should_return_retry_delay_after_intermittent_failure_followed_by_non_intermittent_failure)
Expand All @@ -46,20 +46,20 @@ TEST_F(RetryPolicyTest, should_reset_retry_delay)
policy.RetryDelay(true);
policy.Reset();

ASSERT_EQ(std::chrono::minutes(1), policy.RetryDelay(true));
EXPECT_EQ(std::chrono::minutes(1), policy.RetryDelay(true));
}

TEST_F(RetryPolicyTest, should_return_maximum_retry_delay_when_maximum_is_reached)
{
infra::RetryPolicyExponentialBackoff policy(std::chrono::minutes(4));

ASSERT_EQ(std::chrono::minutes(1), policy.RetryDelay(true));
ASSERT_EQ(std::chrono::minutes(2), policy.RetryDelay(true));
ASSERT_EQ(std::chrono::minutes(4), policy.RetryDelay(true));
ASSERT_EQ(std::chrono::minutes(4), policy.RetryDelay(true));
EXPECT_EQ(std::chrono::minutes(1), policy.RetryDelay(true));
EXPECT_EQ(std::chrono::minutes(2), policy.RetryDelay(true));
EXPECT_EQ(std::chrono::minutes(4), policy.RetryDelay(true));
EXPECT_EQ(std::chrono::minutes(4), policy.RetryDelay(true));
}

TEST_F(RetryPolicyTest, should_return_initial_retry_delay_after_waiting_for_maximum_delay_time)
TEST_F(RetryPolicyTest, should_return_high_retry_delay_after_waiting_for_maximum_delay_time)
{
infra::RetryPolicyExponentialBackoff policy(std::chrono::minutes(4));

Expand All @@ -68,7 +68,7 @@ TEST_F(RetryPolicyTest, should_return_initial_retry_delay_after_waiting_for_maxi

ForwardTime(std::chrono::minutes(4));

ASSERT_EQ(std::chrono::minutes(1), policy.RetryDelay(true));
EXPECT_EQ(std::chrono::hours(1), policy.RetryDelay(true));
}

TEST_F(RetryPolicyTest, should_return_fixed_interval)
Expand Down

0 comments on commit 386af63

Please sign in to comment.