in DarabonbaUnitTests/CoreTest.cs [456:704]
public void TestGetBackoffDelay()
{
BackoffPolicy backoffPolicy = new ExponentialBackoffPolicy(200, 60 * 1000);
RetryCondition retryCondition1 = new RetryCondition
{
MaxAttempts = 1,
Backoff = backoffPolicy,
Exception = new List<string> { "AException" },
ErrorCode = new List<string> { "BExceptionCode" }
};
RetryCondition retryCondition2 = new RetryCondition
{
MaxAttempts = 2,
Backoff = backoffPolicy,
Exception = new List<string> { "AException", "CException" }
};
RetryCondition retryCondition3 = new RetryCondition
{
Exception = new List<string> { "BException" }
};
RetryPolicyContext retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 0,
Exception = new AException
{
Message = "AException",
Code = "AExceptionCode"
}
};
Assert.Equal(0, Core.GetBackoffDelay(null, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 1,
Exception = new AException
{
Message = "AException",
Code = "AExceptionCode"
}
};
Assert.Equal(100, Core.GetBackoffDelay(null, retryPolicyContext));
RetryOptions retryOptions = new RetryOptions
{
Retryable = false,
RetryCondition = null,
NoRetryCondition = null
};
Assert.Equal(100, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryOptions = new RetryOptions
{
Retryable = true,
RetryCondition = new List<RetryCondition> { retryCondition1, retryCondition2 },
NoRetryCondition = new List<RetryCondition> { retryCondition3 }
};
Assert.Equal(400, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 2,
Exception = new AException
{
Message = "AException",
Code = "AExceptionCode"
}
};
Assert.Equal(800, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 1,
Exception = new BException
{
Message = "BException",
Code = "BExceptionCode"
}
};
Assert.Equal(400, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 1,
Exception = new CException
{
Message = "CException",
Code = "CExceptionCode"
}
};
Assert.Equal(400, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 2,
Exception = new CException
{
Message = "CException",
Code = "CExceptionCode"
}
};
Assert.Equal(800, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 3,
Exception = new CException
{
Message = "CException",
Code = "CExceptionCode"
}
};
Assert.Equal(1600, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
RetryCondition retryCondition4 = new RetryCondition
{
MaxAttempts = 20,
Backoff = backoffPolicy,
Exception = new List<string> { "AException" }
};
retryOptions = new RetryOptions
{
RetryCondition = new List<RetryCondition> { retryCondition4 }
};
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 10,
Exception = new AException
{
Message = "AException",
Code = "AExceptionCode"
}
};
Assert.Equal(60000, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
backoffPolicy = new ExponentialBackoffPolicy(200, 180 * 1000);
retryCondition4 = new RetryCondition
{
MaxAttempts = 20,
Backoff = backoffPolicy,
Exception = new List<string> { "AException" }
};
retryOptions = new RetryOptions
{
Retryable = true,
RetryCondition = new List<RetryCondition> { retryCondition4 }
};
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 10,
Exception = new AException
{
Message = "AException",
Code = "AExceptionCode"
}
};
Assert.Equal(120000, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 15,
Exception = new AException
{
Message = "AException",
Code = "AExceptionCode"
}
};
Assert.Equal(120000, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryCondition4 = new RetryCondition
{
MaxAttempts = 20,
MaxDelayTimeMillis = 30 * 1000,
Backoff = backoffPolicy,
Exception = new List<string> { "AException" }
};
retryOptions = new RetryOptions
{
Retryable = true,
RetryCondition = new List<RetryCondition> { retryCondition4 }
};
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 10,
Exception = new AException
{
Message = "AException",
Code = "AExceptionCode"
}
};
Assert.Equal(30000, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 15,
Exception = new AException
{
Message = "AException",
Code = "AExceptionCode"
}
};
Assert.Equal(30000, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
retryCondition4 = new RetryCondition
{
MaxAttempts = 20,
Backoff = null,
Exception = new List<string> { "AException" }
};
retryOptions = new RetryOptions
{
Retryable = true,
RetryCondition = new List<RetryCondition> { retryCondition4 }
};
retryPolicyContext = new RetryPolicyContext
{
RetriesAttempted = 10,
Exception = new AException
{
Message = "AException",
Code = "AExceptionCode"
}
};
Assert.Equal(100, Core.GetBackoffDelay(retryOptions, retryPolicyContext));
}