cs-codex-dist-tests/ContinuousTests/Tests/PerformanceTests.cs

87 lines
2.4 KiB
C#
Raw Normal View History

2023-06-21 09:45:45 +00:00
using DistTestCore;
using DistTestCore.Codex;
using NUnit.Framework;
namespace ContinuousTests.Tests
{
2023-06-25 08:55:55 +00:00
public class UploadPerformanceTest : PerformanceTest
{
public override int RequiredNumberOfNodes => 1;
[TestMoment(t: Zero)]
public void UploadTest()
{
UploadTest(100, Nodes[0]);
}
}
public class DownloadLocalPerformanceTest : PerformanceTest
{
public override int RequiredNumberOfNodes => 1;
[TestMoment(t: Zero)]
public void DownloadTest()
{
DownloadTest(100, Nodes[0], Nodes[0]);
}
}
public class DownloadRemotePerformanceTest : PerformanceTest
{
public override int RequiredNumberOfNodes => 2;
[TestMoment(t: Zero)]
public void DownloadTest()
{
DownloadTest(100, Nodes[0], Nodes[1]);
}
}
public abstract class PerformanceTest : ContinuousTest
{
public override TimeSpan RunTestEvery => TimeSpan.FromHours(1);
public override TestFailMode TestFailMode => TestFailMode.AlwaysRunAllMoments;
2023-06-29 14:07:49 +00:00
public void UploadTest(int megabytes, CodexAccess uploadNode)
2023-06-25 08:55:55 +00:00
{
var file = FileManager.GenerateTestFile(megabytes.MB());
var time = Measure(() =>
{
UploadFile(uploadNode, file);
});
var timePerMB = time / megabytes;
Assert.That(timePerMB, Is.LessThan(CodexContainerRecipe.MaxUploadTimePerMegabyte), "MaxUploadTimePerMegabyte performance threshold breached.");
}
2023-06-29 14:07:49 +00:00
public void DownloadTest(int megabytes, CodexAccess uploadNode, CodexAccess downloadNode)
2023-06-25 08:55:55 +00:00
{
var file = FileManager.GenerateTestFile(megabytes.MB());
var cid = UploadFile(uploadNode, file);
Assert.That(cid, Is.Not.Null);
TestFile? result = null;
var time = Measure(() =>
{
2023-06-28 13:11:20 +00:00
result = DownloadFile(downloadNode, cid!);
2023-06-25 08:55:55 +00:00
});
file.AssertIsEqual(result);
var timePerMB = time / megabytes;
Assert.That(timePerMB, Is.LessThan(CodexContainerRecipe.MaxDownloadTimePerMegabyte), "MaxDownloadTimePerMegabyte performance threshold breached.");
}
private static TimeSpan Measure(Action action)
{
var start = DateTime.UtcNow;
action();
return DateTime.UtcNow - start;
}
}
2023-06-21 09:45:45 +00:00
}