Fixes storage quota for large file tests.
This commit is contained in:
parent
d2d7f3dea5
commit
7ae03938c3
|
@ -1,8 +1,9 @@
|
||||||
namespace DistTestCore
|
using Utils;
|
||||||
|
|
||||||
|
namespace DistTestCore
|
||||||
{
|
{
|
||||||
public class ByteSize
|
public class ByteSize
|
||||||
{
|
{
|
||||||
private static readonly string[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
|
|
||||||
|
|
||||||
public ByteSize(long sizeInBytes)
|
public ByteSize(long sizeInBytes)
|
||||||
{
|
{
|
||||||
|
@ -29,11 +30,7 @@
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
if (SizeInBytes == 0) return "0" + sizeSuffixes[0];
|
return Formatter.FormatByteSize(SizeInBytes);
|
||||||
|
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace DistTestCore
|
||||||
{
|
{
|
||||||
var result = CreateEmptyTestFile(label);
|
var result = CreateEmptyTestFile(label);
|
||||||
GenerateFileBytes(result, size);
|
GenerateFileBytes(result, size);
|
||||||
log.Log($"Generated {size} of content for file '{result.Describe()}'.");
|
log.Log($"Generated file '{result.Describe()}'.");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,12 +117,6 @@ namespace DistTestCore
|
||||||
public string Filename { get; }
|
public string Filename { get; }
|
||||||
public string Label { get; }
|
public string Label { get; }
|
||||||
|
|
||||||
public long GetFileSize()
|
|
||||||
{
|
|
||||||
var info = new FileInfo(Filename);
|
|
||||||
return info.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AssertIsEqual(TestFile? actual)
|
public void AssertIsEqual(TestFile? actual)
|
||||||
{
|
{
|
||||||
if (actual == null) Assert.Fail("TestFile is null.");
|
if (actual == null) Assert.Fail("TestFile is null.");
|
||||||
|
@ -157,7 +151,13 @@ namespace DistTestCore
|
||||||
public string Describe()
|
public string Describe()
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(Label)) return Label;
|
if (!string.IsNullOrEmpty(Label)) return Label;
|
||||||
return Filename;
|
return $"'{Filename}' ({Formatter.FormatByteSize(GetFileSize())})";
|
||||||
|
}
|
||||||
|
|
||||||
|
private long GetFileSize()
|
||||||
|
{
|
||||||
|
var info = new FileInfo(Filename);
|
||||||
|
return info.Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ namespace DistTestCore
|
||||||
{
|
{
|
||||||
using var fileStream = File.OpenRead(file.Filename);
|
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, () =>
|
var response = Stopwatch.Measure(lifecycle.Log, logMessage, () =>
|
||||||
{
|
{
|
||||||
return CodexAccess.UploadFile(fileStream);
|
return CodexAccess.UploadFile(fileStream);
|
||||||
|
@ -91,7 +91,7 @@ namespace DistTestCore
|
||||||
var logMessage = $"Downloading for contentId: '{contentId.Id}'...";
|
var logMessage = $"Downloading for contentId: '{contentId.Id}'...";
|
||||||
var file = lifecycle.FileManager.CreateEmptyTestFile(fileLabel);
|
var file = lifecycle.FileManager.CreateEmptyTestFile(fileLabel);
|
||||||
Stopwatch.Measure(lifecycle.Log, logMessage, () => DownloadToFile(contentId.Id, file));
|
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;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,12 @@ namespace TestsLong.BasicTests
|
||||||
[Values(1, 10, 100, 1024)] int sizeInMB,
|
[Values(1, 10, 100, 1024)] int sizeInMB,
|
||||||
[Values(1, 10, 100, 1024)] int multiplier)
|
[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 uploadStart = DateTime.UtcNow;
|
||||||
var cid = node.UploadFile(expectedFile);
|
var cid = node.UploadFile(expectedFile);
|
||||||
|
@ -30,9 +31,9 @@ namespace TestsLong.BasicTests
|
||||||
AssertTimeConstraint(uploadStart, downloadStart, downloadFinished, size);
|
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 uploadTimePerMB = (uploadStart - downloadStart) / sizeInMB;
|
||||||
var downloadTimePerMB = (downloadStart - downloadFinished) / sizeInMB;
|
var downloadTimePerMB = (downloadStart - downloadFinished) / sizeInMB;
|
||||||
|
|
||||||
|
@ -41,7 +42,6 @@ namespace TestsLong.BasicTests
|
||||||
|
|
||||||
Assert.That(downloadTimePerMB, Is.LessThan(CodexContainerRecipe.MaxDownloadTimePerMegabyte),
|
Assert.That(downloadTimePerMB, Is.LessThan(CodexContainerRecipe.MaxDownloadTimePerMegabyte),
|
||||||
"MaxDownloadTimePerMegabyte performance threshold breached.");
|
"MaxDownloadTimePerMegabyte performance threshold breached.");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,26 +26,5 @@ namespace TestsLong.BasicTests
|
||||||
Assert.That(!string.IsNullOrEmpty(n.GetDebugInfo().id));
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue