Faster test file generation.
This commit is contained in:
parent
7ae03938c3
commit
677ead4fd3
|
@ -15,7 +15,7 @@ namespace DistTestCore
|
|||
|
||||
public class FileManager : IFileManager
|
||||
{
|
||||
public const int ChunkSize = 1024 * 1024;
|
||||
public const int ChunkSize = 1024 * 1024 * 100;
|
||||
private static NumberSource folderNumberSource = new NumberSource(0);
|
||||
private readonly Random random = new Random();
|
||||
private readonly TestLog log;
|
||||
|
@ -41,9 +41,9 @@ namespace DistTestCore
|
|||
|
||||
public TestFile GenerateTestFile(ByteSize size, string label)
|
||||
{
|
||||
var result = CreateEmptyTestFile(label);
|
||||
GenerateFileBytes(result, size);
|
||||
log.Log($"Generated file '{result.Describe()}'.");
|
||||
var sw = Stopwatch.Begin(log);
|
||||
var result = GenerateFile(size, label);
|
||||
sw.End($"Generated file '{result.Describe()}'.");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -73,15 +73,51 @@ namespace DistTestCore
|
|||
}
|
||||
}
|
||||
|
||||
private TestFile GenerateFile(ByteSize size, string label)
|
||||
{
|
||||
var result = CreateEmptyTestFile(label);
|
||||
CheckSpaceAvailable(result, size);
|
||||
|
||||
GenerateFileBytes(result, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void CheckSpaceAvailable(TestFile testFile, ByteSize size)
|
||||
{
|
||||
var file = new FileInfo(testFile.Filename);
|
||||
var drive = new DriveInfo(file.Directory!.Root.FullName);
|
||||
|
||||
var spaceAvailable = drive.TotalFreeSpace;
|
||||
|
||||
if (spaceAvailable < size.SizeInBytes)
|
||||
{
|
||||
var msg = $"Inconclusive: Not enough disk space to perform test. " +
|
||||
$"{Formatter.FormatByteSize(size.SizeInBytes)} required. " +
|
||||
$"{Formatter.FormatByteSize(spaceAvailable)} available.";
|
||||
|
||||
log.Log(msg);
|
||||
Assert.Inconclusive(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateFileBytes(TestFile result, ByteSize size)
|
||||
{
|
||||
long bytesLeft = size.SizeInBytes;
|
||||
int chunkSize = ChunkSize;
|
||||
while (bytesLeft > 0)
|
||||
{
|
||||
var length = Math.Min(bytesLeft, ChunkSize);
|
||||
try
|
||||
{
|
||||
var length = Math.Min(bytesLeft, chunkSize);
|
||||
AppendRandomBytesToFile(result, length);
|
||||
bytesLeft -= length;
|
||||
}
|
||||
catch
|
||||
{
|
||||
chunkSize = chunkSize / 2;
|
||||
if (chunkSize < 1024) throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AppendRandomBytesToFile(TestFile result, long length)
|
||||
|
|
|
@ -1,20 +1,47 @@
|
|||
using DistTestCore;
|
||||
using DistTestCore.Codex;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.Interfaces;
|
||||
|
||||
namespace TestsLong.BasicTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class LargeFileTests : DistTest
|
||||
{
|
||||
[Test]
|
||||
[Combinatorial]
|
||||
[UseLongTimeouts]
|
||||
public void DownloadCorrectnessTest(
|
||||
[Values(1, 10, 100, 1024)] int sizeInMB,
|
||||
[Values(1, 10, 100, 1024)] int multiplier)
|
||||
#region Abort test run after first failure
|
||||
|
||||
private bool stop;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
if (stop)
|
||||
{
|
||||
Assert.Inconclusive("Previous test failed");
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
|
||||
{
|
||||
stop = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[TestCase( 1 * 1)] // 1 MB
|
||||
[TestCase( 1 * 10)]
|
||||
[TestCase( 1 * 100)]
|
||||
[TestCase( 1 * 1024)] // 1 GB
|
||||
[TestCase( 1024 * 10)]
|
||||
[TestCase( 1024 * 100)]
|
||||
[TestCase( 1024 * 1024)] // 1 TB :O
|
||||
[UseLongTimeouts]
|
||||
public void DownloadCorrectnessTest(long size)
|
||||
{
|
||||
long size = (sizeInMB * multiplier);
|
||||
var sizeMB = size.MB();
|
||||
|
||||
var expectedFile = GenerateTestFile(sizeMB);
|
||||
|
|
Loading…
Reference in New Issue