Merge pull request #2 from Shorssaud/master

Adding Multi Download / Upload tests
This commit is contained in:
Shaun Orssaud 2023-04-26 15:01:10 +02:00 committed by GitHub
commit 75b8d39cc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.vs
obj
bin
.vscode

View File

@ -3,6 +3,7 @@
public class LogFile
{
private readonly string extension;
private readonly object fileLock = new object();
private string filename;
public LogFile(string filename, string extension)
@ -25,7 +26,10 @@
{
try
{
File.AppendAllLines(FullFilename, new[] { message });
lock (fileLock)
{
File.AppendAllLines(FullFilename, new[] { message });
}
}
catch (Exception ex)
{

View File

@ -0,0 +1,51 @@
using DistTestCore;
using KubernetesWorkflow;
using NUnit.Framework;
namespace Tests.ParallelTests
{
[TestFixture]
public class DownloadTests : DistTest
{
[Test]
public void ThreeNodeDownloads()
{
ParallelDownload(3, 5000.MB());
}
[Test]
public void FiveNodeDownloads()
{
ParallelDownload(5, 1000.MB());
}
[Test]
public void TenNodeDownloads()
{
ParallelDownload(10, 256.MB());
}
void ParallelDownload(int numberOfNodes, ByteSize filesize)
{
var group = SetupCodexNodes(numberOfNodes).BringOnline();
var host = SetupCodexNodes(1).BringOnline()[0];
foreach (var node in group)
{
host.ConnectToPeer(node);
}
var testFile = GenerateTestFile(filesize);
var contentId = host.UploadFile(testFile);
var list = new List<Task<TestFile?>>();
foreach (var node in group)
{
list.Add(Task.Run(() => { return node.DownloadContent(contentId); }));
}
Task.WaitAll(list.ToArray());
foreach (var task in list)
{
testFile.AssertIsEqual(task.Result);
}
}
}
}

View File

@ -0,0 +1,56 @@
using DistTestCore;
using KubernetesWorkflow;
using NUnit.Framework;
namespace Tests.ParallelTests
{
[TestFixture]
public class UploadTests : DistTest
{
[Test]
public void ThreeNodeUploads()
{
ParallelUpload(3, 50.MB());
}
[Test]
public void FiveNodeUploads()
{
ParallelUpload(5, 750.MB());
}
[Test]
public void TenNodeUploads()
{
ParallelUpload(10, 25.MB());
}
void ParallelUpload(int numberOfNodes, ByteSize filesize)
{
var group = SetupCodexNodes(numberOfNodes).BringOnline();
var host = SetupCodexNodes(1).BringOnline()[0];
foreach (var node in group)
{
host.ConnectToPeer(node);
}
var testfiles = new List<TestFile>();
var contentIds = new List<Task<ContentId>>();
for (int i = 0; i < group.Count(); i++)
{
testfiles.Add(GenerateTestFile(filesize));
var n = i;
contentIds.Add(Task.Run(() => { return host.UploadFile(testfiles[n]); }));
}
var downloads = new List<Task<TestFile?>>();
for (int i = 0; i < group.Count(); i++)
{
var n = i;
downloads.Add(Task.Run(() => { return group[n].DownloadContent(contentIds[n].Result); }));
}
Task.WaitAll(downloads.ToArray());
for (int i = 0; i < group.Count(); i++)
{
testfiles[i].AssertIsEqual(downloads[i].Result);
}
}
}
}