diff --git a/DistTestCore/ByteSize.cs b/DistTestCore/ByteSize.cs index dc288bc..4760c83 100644 --- a/DistTestCore/ByteSize.cs +++ b/DistTestCore/ByteSize.cs @@ -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]; } } diff --git a/DistTestCore/FileManager.cs b/DistTestCore/FileManager.cs index 62b5ba7..f2737fa 100644 --- a/DistTestCore/FileManager.cs +++ b/DistTestCore/FileManager.cs @@ -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; } diff --git a/DistTestCore/Helpers/PeerDownloadTestHelpers.cs b/DistTestCore/Helpers/PeerDownloadTestHelpers.cs index 1e8812c..0ce642b 100644 --- a/DistTestCore/Helpers/PeerDownloadTestHelpers.cs +++ b/DistTestCore/Helpers/PeerDownloadTestHelpers.cs @@ -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 nodes) - { - AssertFullDownloadInterconnectivity(nodes, 1.MB()); - } - public void AssertFullDownloadInterconnectivity(IEnumerable 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) diff --git a/KubernetesWorkflow/K8sController.cs b/KubernetesWorkflow/K8sController.cs index e0f8627..6174291 100644 --- a/KubernetesWorkflow/K8sController.cs +++ b/KubernetesWorkflow/K8sController.cs @@ -391,6 +391,7 @@ namespace KubernetesWorkflow { Name = recipe.Name, Image = recipe.Image, + ImagePullPolicy = "Always", Ports = CreateContainerPorts(recipe), Env = CreateEnv(recipe) }; diff --git a/LongTests/BasicTests/DownloadTests.cs b/LongTests/BasicTests/DownloadTests.cs index 5034462..828cdaa 100644 --- a/LongTests/BasicTests/DownloadTests.cs +++ b/LongTests/BasicTests/DownloadTests.cs @@ -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)] diff --git a/Tests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs b/Tests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs index b1e9bd6..ff3f62e 100644 --- a/Tests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs +++ b/Tests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs @@ -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()); } } }