Allows for the use of UseLongTimeouts in combination with test-case attribute
This commit is contained in:
parent
d236fe6cea
commit
96c2ade7ff
|
@ -5,6 +5,7 @@ using DistTestCore.Metrics;
|
|||
using KubernetesWorkflow;
|
||||
using Logging;
|
||||
using NUnit.Framework;
|
||||
using System.Reflection;
|
||||
using Utils;
|
||||
|
||||
namespace DistTestCore
|
||||
|
@ -13,15 +14,23 @@ namespace DistTestCore
|
|||
public abstract class DistTest
|
||||
{
|
||||
private readonly Configuration configuration = new Configuration();
|
||||
private readonly Assembly[] testAssemblies;
|
||||
private FixtureLog fixtureLog = null!;
|
||||
private TestLifecycle lifecycle = null!;
|
||||
private DateTime testStart = DateTime.MinValue;
|
||||
|
||||
public DistTest()
|
||||
{
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
testAssemblies = assemblies.Where(a => a.FullName!.ToLowerInvariant().Contains("test")).ToArray();
|
||||
}
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void GlobalSetup()
|
||||
{
|
||||
// Previous test run may have been interrupted.
|
||||
// Begin by cleaning everything up.
|
||||
Timing.UseLongTimeouts = false;
|
||||
fixtureLog = new FixtureLog(configuration.GetLogConfig());
|
||||
|
||||
try
|
||||
|
@ -48,6 +57,8 @@ namespace DistTestCore
|
|||
[SetUp]
|
||||
public void SetUpDistTest()
|
||||
{
|
||||
Timing.UseLongTimeouts = ShouldUseLongTimeouts();
|
||||
|
||||
if (GlobalTestFailure.HasFailed)
|
||||
{
|
||||
Assert.Inconclusive("Skip test: Previous test failed during clean up.");
|
||||
|
@ -58,6 +69,21 @@ namespace DistTestCore
|
|||
}
|
||||
}
|
||||
|
||||
private bool ShouldUseLongTimeouts()
|
||||
{
|
||||
// Don't be fooled! TestContext.CurrentTest.Test allows you easy access to the attributes of the current test.
|
||||
// But this doesn't work for tests making use of [TestCase]. So instead, we use reflection here to figure out
|
||||
// if the attribute is present.
|
||||
var currentTest = TestContext.CurrentContext.Test;
|
||||
var className = currentTest.ClassName;
|
||||
var methodName = currentTest.MethodName;
|
||||
|
||||
var testClasses = testAssemblies.SelectMany(a => a.GetTypes()).Where(c => c.FullName == className).ToArray();
|
||||
var testMethods = testClasses.SelectMany(c => c.GetMethods()).Where(m => m.Name == methodName).ToArray();
|
||||
|
||||
return testMethods.Any(m => m.GetCustomAttribute<UseLongTimeoutsAttribute>() != null);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDownDistTest()
|
||||
{
|
||||
|
|
|
@ -6,15 +6,12 @@ namespace DistTestCore
|
|||
[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 bool UseLongTimeouts { get; set; }
|
||||
|
||||
|
||||
public static TimeSpan HttpCallTimeout()
|
||||
{
|
||||
|
@ -48,8 +45,7 @@ namespace DistTestCore
|
|||
|
||||
private static ITimeSet GetTimes()
|
||||
{
|
||||
var testProperties = TestContext.CurrentContext.Test.Properties;
|
||||
if (testProperties.ContainsKey(UseLongTimeoutsKey)) return new LongTimeSet();
|
||||
if (UseLongTimeouts) return new LongTimeSet();
|
||||
return new DefaultTimeSet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,16 @@
|
|||
using DistTestCore;
|
||||
using KubernetesWorkflow;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Tests.ParallelTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class DownloadTests : DistTest
|
||||
{
|
||||
[Test]
|
||||
public void ThreeNodeDownloads()
|
||||
{
|
||||
ParallelDownload(3, 5000.MB());
|
||||
}
|
||||
[Test]
|
||||
public void FiveNodeDownloads()
|
||||
{
|
||||
ParallelDownload(5, 1000.MB());
|
||||
}
|
||||
[Test]
|
||||
public void TenNodeDownloads()
|
||||
{
|
||||
ParallelDownload(10, 256.MB());
|
||||
}
|
||||
|
||||
void ParallelDownload(int numberOfNodes, ByteSize filesize)
|
||||
[TestCase(3, 50)]
|
||||
[TestCase(5, 750)]
|
||||
[TestCase(10, 25)]
|
||||
[UseLongTimeouts]
|
||||
public void ParallelDownload(int numberOfNodes, int filesizeMb)
|
||||
{
|
||||
var group = SetupCodexNodes(numberOfNodes);
|
||||
var host = SetupCodexNode();
|
||||
|
@ -32,7 +20,7 @@ namespace Tests.ParallelTests
|
|||
host.ConnectToPeer(node);
|
||||
}
|
||||
|
||||
var testFile = GenerateTestFile(filesize);
|
||||
var testFile = GenerateTestFile(filesizeMb.MB());
|
||||
var contentId = host.UploadFile(testFile);
|
||||
var list = new List<Task<TestFile?>>();
|
||||
|
||||
|
|
|
@ -1,27 +1,16 @@
|
|||
using DistTestCore;
|
||||
using KubernetesWorkflow;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Tests.ParallelTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class UploadTests : DistTest
|
||||
{
|
||||
[Test]
|
||||
public void ThreeNodeUploads()
|
||||
{
|
||||
ParallelUpload(3, 50.MB());
|
||||
}
|
||||
[Test]
|
||||
public void FiveNodeUploads()
|
||||
{
|
||||
ParallelUpload(5, 750.MB());
|
||||
}
|
||||
[Test]
|
||||
public void TenNodeUploads()
|
||||
{
|
||||
ParallelUpload(10, 25.MB());
|
||||
}
|
||||
void ParallelUpload(int numberOfNodes, ByteSize filesize)
|
||||
[TestCase(3, 50)]
|
||||
[TestCase(5, 750)]
|
||||
[TestCase(10, 25)]
|
||||
[UseLongTimeouts]
|
||||
public void ParallelUpload(int numberOfNodes, int filesizeMb)
|
||||
{
|
||||
var group = SetupCodexNodes(numberOfNodes);
|
||||
var host = SetupCodexNode();
|
||||
|
@ -36,7 +25,7 @@ namespace Tests.ParallelTests
|
|||
|
||||
for (int i = 0; i < group.Count(); i++)
|
||||
{
|
||||
testfiles.Add(GenerateTestFile(filesize));
|
||||
testfiles.Add(GenerateTestFile(filesizeMb.MB()));
|
||||
var n = i;
|
||||
contentIds.Add(Task.Run(() => { return host.UploadFile(testfiles[n]); }));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue