From 7ae03938c379c45f5c78ee405a3d28cd3c89d641 Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 7 Jun 2023 09:32:56 +0200 Subject: [PATCH] Fixes storage quota for large file tests. --- DistTestCore/ByteSize.cs | 11 ++++------- DistTestCore/FileManager.cs | 16 ++++++++-------- DistTestCore/OnlineCodexNode.cs | 4 ++-- LongTests/BasicTests/LargeFileTests.cs | 12 ++++++------ LongTests/BasicTests/TestInfraTests.cs | 21 --------------------- Utils/Formatter.cs | 16 ++++++++++++++++ 6 files changed, 36 insertions(+), 44 deletions(-) create mode 100644 Utils/Formatter.cs diff --git a/DistTestCore/ByteSize.cs b/DistTestCore/ByteSize.cs index 28ec49c..8d47cf2 100644 --- a/DistTestCore/ByteSize.cs +++ b/DistTestCore/ByteSize.cs @@ -1,8 +1,9 @@ -namespace DistTestCore +using Utils; + +namespace DistTestCore { public class ByteSize { - private static readonly string[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; public ByteSize(long sizeInBytes) { @@ -29,11 +30,7 @@ public override string ToString() { - 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]; + return Formatter.FormatByteSize(SizeInBytes); } } diff --git a/DistTestCore/FileManager.cs b/DistTestCore/FileManager.cs index f2737fa..b9f2264 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} of content for file '{result.Describe()}'."); + log.Log($"Generated file '{result.Describe()}'."); return result; } @@ -117,12 +117,6 @@ namespace DistTestCore public string Filename { get; } public string Label { get; } - public long GetFileSize() - { - var info = new FileInfo(Filename); - return info.Length; - } - public void AssertIsEqual(TestFile? actual) { if (actual == null) Assert.Fail("TestFile is null."); @@ -157,7 +151,13 @@ namespace DistTestCore public string Describe() { if (!string.IsNullOrEmpty(Label)) return Label; - return Filename; + return $"'{Filename}' ({Formatter.FormatByteSize(GetFileSize())})"; + } + + private long GetFileSize() + { + var info = new FileInfo(Filename); + return info.Length; } } } diff --git a/DistTestCore/OnlineCodexNode.cs b/DistTestCore/OnlineCodexNode.cs index 46ca044..d53f2c2 100644 --- a/DistTestCore/OnlineCodexNode.cs +++ b/DistTestCore/OnlineCodexNode.cs @@ -69,7 +69,7 @@ namespace DistTestCore { using var fileStream = File.OpenRead(file.Filename); - var logMessage = $"Uploading file '{file.Describe()}' of size {file.GetFileSize()}..."; + var logMessage = $"Uploading file {file.Describe()}..."; var response = Stopwatch.Measure(lifecycle.Log, logMessage, () => { return CodexAccess.UploadFile(fileStream); @@ -91,7 +91,7 @@ namespace DistTestCore var logMessage = $"Downloading for contentId: '{contentId.Id}'..."; var file = lifecycle.FileManager.CreateEmptyTestFile(fileLabel); Stopwatch.Measure(lifecycle.Log, logMessage, () => DownloadToFile(contentId.Id, file)); - Log($"Downloaded file '{file.Describe()}' of size {file.GetFileSize()} to '{file.Filename}'."); + Log($"Downloaded file {file.Describe()} to '{file.Filename}'."); return file; } diff --git a/LongTests/BasicTests/LargeFileTests.cs b/LongTests/BasicTests/LargeFileTests.cs index 636ff79..a96184d 100644 --- a/LongTests/BasicTests/LargeFileTests.cs +++ b/LongTests/BasicTests/LargeFileTests.cs @@ -14,11 +14,12 @@ namespace TestsLong.BasicTests [Values(1, 10, 100, 1024)] int sizeInMB, [Values(1, 10, 100, 1024)] int multiplier) { - var size = (sizeInMB * multiplier).MB(); + long size = (sizeInMB * multiplier); + var sizeMB = size.MB(); - var expectedFile = GenerateTestFile(size); + var expectedFile = GenerateTestFile(sizeMB); - var node = SetupCodexNode(); + var node = SetupCodexNode(s => s.WithStorageQuota((size + 10).MB())); var uploadStart = DateTime.UtcNow; var cid = node.UploadFile(expectedFile); @@ -30,9 +31,9 @@ namespace TestsLong.BasicTests AssertTimeConstraint(uploadStart, downloadStart, downloadFinished, size); } - private void AssertTimeConstraint(DateTime uploadStart, DateTime downloadStart, DateTime downloadFinished, ByteSize size) + private void AssertTimeConstraint(DateTime uploadStart, DateTime downloadStart, DateTime downloadFinished, long size) { - float sizeInMB = size.ToMB(); + float sizeInMB = size; var uploadTimePerMB = (uploadStart - downloadStart) / sizeInMB; var downloadTimePerMB = (downloadStart - downloadFinished) / sizeInMB; @@ -41,7 +42,6 @@ namespace TestsLong.BasicTests Assert.That(downloadTimePerMB, Is.LessThan(CodexContainerRecipe.MaxDownloadTimePerMegabyte), "MaxDownloadTimePerMegabyte performance threshold breached."); - } } } diff --git a/LongTests/BasicTests/TestInfraTests.cs b/LongTests/BasicTests/TestInfraTests.cs index 9b3111f..a6f68e3 100644 --- a/LongTests/BasicTests/TestInfraTests.cs +++ b/LongTests/BasicTests/TestInfraTests.cs @@ -26,26 +26,5 @@ namespace TestsLong.BasicTests Assert.That(!string.IsNullOrEmpty(n.GetDebugInfo().id)); } } - - [Test, UseLongTimeouts] - public void DownloadConsistencyTest() - { - var primary = SetupCodexNode(s => s - .WithStorageQuota(2.MB())); - - var testFile = GenerateTestFile(1.MB()); - - var contentId = primary.UploadFile(testFile); - - var files = new List(); - for (var i = 0; i < 100; i++) - { - files.Add(primary.DownloadContent(contentId)); - } - - Assert.That(files.All(f => f != null)); - Assert.That(files.All(f => f!.GetFileSize() == testFile.GetFileSize())); - foreach (var file in files) file!.AssertIsEqual(testFile); - } } } diff --git a/Utils/Formatter.cs b/Utils/Formatter.cs new file mode 100644 index 0000000..1ea1550 --- /dev/null +++ b/Utils/Formatter.cs @@ -0,0 +1,16 @@ +namespace Utils +{ + public static class Formatter + { + private static readonly string[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; + + public static string FormatByteSize(long bytes) + { + if (bytes == 0) return "0" + sizeSuffixes[0]; + + var sizeOrder = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024))); + var digit = Math.Round(bytes / Math.Pow(1024, sizeOrder), 1); + return digit.ToString() + sizeSuffixes[sizeOrder]; + } + } +}