cs-codex-dist-tests/CodexDistTestCore/Timing.cs

132 lines
3.0 KiB
C#
Raw Normal View History

using NUnit.Framework;
2023-03-21 12:20:21 +00:00
namespace CodexDistTestCore
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class UseLongTimeoutsAttribute : PropertyAttribute
{
public UseLongTimeoutsAttribute()
: base(Timing.UseLongTimeoutsKey)
{
}
}
public static class Timing
{
public const string UseLongTimeoutsKey = "UseLongTimeouts";
public static TimeSpan HttpCallTimeout()
{
return GetTimes().HttpCallTimeout();
2023-03-19 10:40:05 +00:00
}
public static int HttpCallRetryCount()
{
return GetTimes().HttpCallRetryCount();
}
2023-03-23 11:35:03 +00:00
public static void HttpCallRetryDelay()
{
2023-03-23 11:35:03 +00:00
Utils.Sleep(GetTimes().HttpCallRetryDelay());
}
2023-03-19 10:40:05 +00:00
public static void WaitForK8sServiceDelay()
{
Utils.Sleep(GetTimes().WaitForK8sServiceDelay());
}
2023-03-19 10:40:05 +00:00
public static TimeSpan K8sOperationTimeout()
{
return GetTimes().K8sOperationTimeout();
}
2023-03-29 08:07:16 +00:00
public static TimeSpan WaitForMetricTimeout()
{
return GetTimes().WaitForMetricTimeout();
}
private static ITimeSet GetTimes()
{
var testProperties = TestContext.CurrentContext.Test.Properties;
if (testProperties.ContainsKey(UseLongTimeoutsKey)) return new LongTimeSet();
return new DefaultTimeSet();
}
}
public interface ITimeSet
{
TimeSpan HttpCallTimeout();
int HttpCallRetryCount();
2023-03-23 11:35:03 +00:00
TimeSpan HttpCallRetryDelay();
TimeSpan WaitForK8sServiceDelay();
TimeSpan K8sOperationTimeout();
2023-03-29 08:07:16 +00:00
TimeSpan WaitForMetricTimeout();
}
public class DefaultTimeSet : ITimeSet
{
public TimeSpan HttpCallTimeout()
{
return TimeSpan.FromSeconds(10);
}
public int HttpCallRetryCount()
{
return 5;
}
2023-03-23 11:35:03 +00:00
public TimeSpan HttpCallRetryDelay()
{
return TimeSpan.FromSeconds(3);
}
public TimeSpan WaitForK8sServiceDelay()
{
return TimeSpan.FromSeconds(1);
}
2023-03-21 12:20:21 +00:00
public TimeSpan K8sOperationTimeout()
{
return TimeSpan.FromMinutes(5);
}
2023-03-29 08:07:16 +00:00
public TimeSpan WaitForMetricTimeout()
{
return TimeSpan.FromSeconds(30);
}
}
public class LongTimeSet : ITimeSet
{
public TimeSpan HttpCallTimeout()
{
2023-03-21 10:41:05 +00:00
return TimeSpan.FromHours(2);
}
public int HttpCallRetryCount()
{
return 2;
}
2023-03-23 11:35:03 +00:00
public TimeSpan HttpCallRetryDelay()
2023-03-19 10:40:05 +00:00
{
return TimeSpan.FromMinutes(5);
}
public TimeSpan WaitForK8sServiceDelay()
{
return TimeSpan.FromSeconds(10);
}
public TimeSpan K8sOperationTimeout()
{
return TimeSpan.FromMinutes(15);
}
2023-03-29 08:07:16 +00:00
public TimeSpan WaitForMetricTimeout()
{
return TimeSpan.FromMinutes(5);
}
}
}