Merge branch 'master' into feature/marketplace-contracts

This commit is contained in:
benbierens 2023-04-26 15:31:26 +02:00
commit e2586ddd26
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
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)
@ -24,9 +25,12 @@
public void WriteRaw(string message)
{
try
{
lock (fileLock)
{
File.AppendAllLines(FullFilename, new[] { message });
}
}
catch (Exception ex)
{
Console.WriteLine("Writing to log has failed: " + 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);
}
}
}
}