Variable size download tests

This commit is contained in:
benbierens 2023-06-06 16:10:30 +02:00
parent e33a6776e5
commit 56dc1c632d
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
6 changed files with 44 additions and 18 deletions

View File

@ -2,8 +2,11 @@
{
public class ByteSize
{
private static readonly string[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
public ByteSize(long sizeInBytes)
{
if (sizeInBytes < 0) throw new ArgumentException("Cannot create ByteSize object with size less than 0. Was: " + sizeInBytes);
SizeInBytes = sizeInBytes;
}
@ -21,7 +24,11 @@
public override string ToString()
{
return $"{SizeInBytes} bytes";
if (SizeInBytes == 0) return "0" + sizeSuffixes[0];
var sizeOrder = Convert.ToInt32(Math.Floor(Math.Log(SizeInBytes, 1024)));
var digit = Math.Round(SizeInBytes / Math.Pow(1024, sizeOrder), 1);
return digit.ToString() + sizeSuffixes[sizeOrder];
}
}

View File

@ -43,7 +43,7 @@ namespace DistTestCore
{
var result = CreateEmptyTestFile(label);
GenerateFileBytes(result, size);
log.Log($"Generated {size.SizeInBytes} bytes of content for file '{result.Describe()}'.");
log.Log($"Generated {size} of content for file '{result.Describe()}'.");
return result;
}

View File

@ -1,5 +1,4 @@
using Nethereum.Model;
using NUnit.Framework;
using NUnit.Framework;
namespace DistTestCore.Helpers
{
@ -12,11 +11,6 @@ namespace DistTestCore.Helpers
this.test = test;
}
public void AssertFullDownloadInterconnectivity(IEnumerable<IOnlineCodexNode> nodes)
{
AssertFullDownloadInterconnectivity(nodes, 1.MB());
}
public void AssertFullDownloadInterconnectivity(IEnumerable<IOnlineCodexNode> nodes, ByteSize testFileSize)
{
test.Log($"Asserting full download interconnectivity for nodes: '{string.Join(",", nodes.Select(n => n.GetName()))}'...");
@ -36,17 +30,21 @@ namespace DistTestCore.Helpers
test.Log($"Success! Full download interconnectivity for nodes: {string.Join(",", nodes.Select(n => n.GetName()))}");
var timeTaken = DateTime.UtcNow - start;
AssertTimePerDownload(timeTaken, nodes.Count());
AssertTimePerDownload(timeTaken, nodes.Count(), testFileSize);
}
private void AssertTimePerDownload(TimeSpan timeTaken, int numberOfNodes)
private void AssertTimePerDownload(TimeSpan timeTaken, int numberOfNodes, ByteSize size)
{
var numberOfDownloads = numberOfNodes * (numberOfNodes - 1);
var timePerDownload = timeTaken / numberOfDownloads;
float sizeInMB = size.SizeInBytes / (1024.0f * 1024.0f);
var timePerMB = timePerDownload.TotalSeconds / sizeInMB;
test.Log($"Performed {numberOfDownloads} downloads in {timeTaken.TotalSeconds} seconds, for an average of {timePerDownload.TotalSeconds} seconds per download.");
test.Log($"Performed {numberOfDownloads} downloads of {size} in {timeTaken.TotalSeconds} seconds, for an average of {timePerMB} seconds per MB.");
Assert.That(timePerDownload.TotalSeconds, Is.LessThan(20.0f), "Seconds-per-Download breached performance threshold.");
var maxTimePerMB = 2.0f;
Assert.That(timePerMB, Is.LessThan(maxTimePerMB), "Seconds-per-MB performance threshold breached.");
}
private void PerformTest(IOnlineCodexNode uploader, IOnlineCodexNode[] downloaders, ByteSize testFileSize)

View File

@ -391,6 +391,7 @@ namespace KubernetesWorkflow
{
Name = recipe.Name,
Image = recipe.Image,
ImagePullPolicy = "Always",
Ports = CreateContainerPorts(recipe),
Env = CreateEnv(recipe)
};

View File

@ -6,6 +6,25 @@ namespace TestsLong.BasicTests
[TestFixture]
public class DownloadTests : DistTest
{
[Test]
[Combinatorial]
[UseLongTimeouts]
public void DownloadCorrectnessTest(
[Values(1, 10, 100, 1024)] int sizeInMB,
[Values(1, 10, 100, 1024)] int multiplier)
{
var size = (sizeInMB * multiplier).MB();
var expectedFile = GenerateTestFile(size);
var node = SetupCodexNode();
var cid = node.UploadFile(expectedFile);
var actualFile = node.DownloadContent(cid);
expectedFile.AssertIsEqual(actualFile);
}
[TestCase(3, 500)]
[TestCase(5, 100)]
[TestCase(10, 256)]

View File

@ -6,14 +6,15 @@ namespace Tests.DownloadConnectivityTests
[TestFixture]
public class FullyConnectedDownloadTests : AutoBootstrapDistTest
{
[TestCase(3)]
[TestCase(10)]
[TestCase(20)]
public void FullyConnectedDownloadTest(int numberOfNodes)
[Test]
[Combinatorial]
public void FullyConnectedDownloadTest(
[Values(3, 10, 20)] int numberOfNodes,
[Values(1, 10, 100)] int sizeMBs)
{
for (var i = 0; i < numberOfNodes; i++) SetupCodexNode();
PeerDownloadTestHelpers.AssertFullDownloadInterconnectivity(GetAllOnlineCodexNodes());
PeerDownloadTestHelpers.AssertFullDownloadInterconnectivity(GetAllOnlineCodexNodes(), sizeMBs.MB());
}
}
}