Fixes storage quota for large file tests.

This commit is contained in:
benbierens 2023-06-07 09:32:56 +02:00
parent d2d7f3dea5
commit 7ae03938c3
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
6 changed files with 36 additions and 44 deletions

View File

@ -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);
}
}

View File

@ -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;
}
}
}

View File

@ -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;
}

View File

@ -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.");
}
}
}

View File

@ -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<TestFile?>();
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);
}
}
}

16
Utils/Formatter.cs Normal file
View File

@ -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];
}
}
}