in DarabonbaUnitTests/CoreTest.cs [715:831]
public void TestThrottlingBackoffDelay()
{
BackoffPolicy backoffPolicy = new ExponentialBackoffPolicy(200, 60 * 1000);
RetryCondition retryCondition = new RetryCondition
{
MaxAttempts = 1,
Backoff = backoffPolicy,
Exception = new List<string> { "ThrottlingException" }
};
RetryPolicyContext retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 1,
Exception = new ThrottlingException { }
};
Assert.Equal(100, Core.GetBackoffDelay(null, retryPolicyContext));
RetryOptions retryOptions = new RetryOptions
{
Retryable = false,
RetryCondition = new List<RetryCondition> { retryCondition },
NoRetryCondition = null
};
Assert.Equal(100, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryOptions = new RetryOptions
{
Retryable = true,
RetryCondition = new List<RetryCondition> { retryCondition },
NoRetryCondition = null
};
Assert.Equal(100, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 1,
Exception = new ThrottlingException
{
Message = "ThrottlingException"
}
};
Assert.Equal(400, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 1,
Exception = new ThrottlingException
{
// TODO retryable true
Message = "ThrottlingException",
RetryAfter = 2000L
}
};
Assert.Equal(2000, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 1,
Exception = new ThrottlingException
{
// TODO retryable true
Message = "ThrottlingException",
RetryAfter = 320 * 1000L
}
};
Assert.Equal(120000, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryCondition = new RetryCondition
{
MaxAttempts = 1,
Backoff = backoffPolicy,
ErrorCode = new List<string> { "Throttling", "Throttling.User", "Throttling.Api" }
};
retryOptions = new RetryOptions
{
Retryable = true,
RetryCondition = new List<RetryCondition> { retryCondition },
NoRetryCondition = null
};
Assert.Equal(100, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 1,
Exception = new ThrottlingException
{
// TODO retryable true
Code = "Throttling",
RetryAfter = 2000L
}
};
Assert.Equal(2000, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 1,
Exception = new ThrottlingException
{
// TODO retryable true
Code = "Throttling.User",
RetryAfter = 2000L
}
};
Assert.Equal(2000, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 1,
Exception = new ThrottlingException
{
// TODO retryable true
Code = "Throttling.Api",
RetryAfter = 2000L
}
};
Assert.Equal(2000, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
}