Flexible timeout values configured from test attribute

This commit is contained in:
benbierens 2023-03-21 09:58:13 +01:00
parent c422b08c96
commit 511c6870ed
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
2 changed files with 108 additions and 5 deletions

View File

@ -1,5 +1,6 @@
using CodexDistTests.TestCore; using CodexDistTests.TestCore;
using NUnit.Framework; using NUnit.Framework;
using System;
namespace CodexDistTests.BasicTests namespace CodexDistTests.BasicTests
{ {
@ -36,6 +37,23 @@ namespace CodexDistTests.BasicTests
testFile.AssertIsEqual(downloadedFile); testFile.AssertIsEqual(downloadedFile);
} }
[Test, UseLongTimeouts]
public void OneClientLargeFileTest()
{
var primary = SetupCodexNode()
.WithLogLevel(CodexLogLevel.Trace)
.WithStorageQuota(100.GB())
.BringOnline();
var testFile = GenerateTestFile(40.GB());
var contentId = primary.UploadFile(testFile);
var downloadedFile = primary.DownloadContent(contentId);
testFile.AssertIsEqual(downloadedFile);
}
//[Test] //[Test]
//public void TwoClientTest() //public void TwoClientTest()
//{ //{

View File

@ -1,30 +1,115 @@
namespace CodexDistTests.TestCore using NUnit.Framework;
namespace CodexDistTests.TestCore
{ {
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class UseLongTimeoutsAttribute : PropertyAttribute
{
public UseLongTimeoutsAttribute()
: base(Timing.UseLongTimeoutsKey)
{
}
}
public static class Timing public static class Timing
{ {
public const string UseLongTimeoutsKey = "UseLongTimeouts";
public static TimeSpan HttpCallTimeout() public static TimeSpan HttpCallTimeout()
{ {
return TimeSpan.FromSeconds(10); return GetTimes().HttpCallTimeout();
} }
public static int HttpCallRetryCount() public static int HttpCallRetryCount()
{ {
return 5; return GetTimes().HttpCallRetryCount();
} }
public static void RetryDelay() public static void RetryDelay()
{ {
Utils.Sleep(TimeSpan.FromSeconds(3)); Utils.Sleep(GetTimes().RetryDelay());
} }
public static void WaitForK8sServiceDelay() public static void WaitForK8sServiceDelay()
{ {
Utils.Sleep(TimeSpan.FromSeconds(1)); Utils.Sleep(GetTimes().WaitForK8sServiceDelay());
} }
public static TimeSpan K8sOperationTimeout() public static TimeSpan K8sOperationTimeout()
{
return GetTimes().K8sOperationTimeout();
}
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();
TimeSpan RetryDelay();
TimeSpan WaitForK8sServiceDelay();
TimeSpan K8sOperationTimeout();
}
public class DefaultTimeSet : ITimeSet
{
public TimeSpan HttpCallTimeout()
{
return TimeSpan.FromSeconds(10);
}
public int HttpCallRetryCount()
{
return 5;
}
public TimeSpan RetryDelay()
{
return TimeSpan.FromSeconds(3);
}
public TimeSpan WaitForK8sServiceDelay()
{
return TimeSpan.FromSeconds(1);
}
public TimeSpan K8sOperationTimeout()
{ {
return TimeSpan.FromMinutes(5); return TimeSpan.FromMinutes(5);
} }
} }
public class LongTimeSet : ITimeSet
{
public TimeSpan HttpCallTimeout()
{
return TimeSpan.FromMinutes(30);
}
public int HttpCallRetryCount()
{
return 2;
}
public TimeSpan RetryDelay()
{
return TimeSpan.FromMinutes(5);
}
public TimeSpan WaitForK8sServiceDelay()
{
return TimeSpan.FromSeconds(10);
}
public TimeSpan K8sOperationTimeout()
{
return TimeSpan.FromMinutes(15);
}
}
} }