cs-codex-dist-tests/Tests/BasicTests/UploadTests.cs

56 lines
1.6 KiB
C#
Raw Normal View History

2023-04-20 13:58:47 +00:00
using DistTestCore;
using KubernetesWorkflow;
2023-04-19 10:34:46 +00:00
using NUnit.Framework;
namespace Tests.ParallelTests
{
[TestFixture]
public class UploadTests : DistTest
{
[Test]
public void ThreeNodeUploads()
2023-04-19 10:34:46 +00:00
{
2023-04-25 11:43:51 +00:00
ParallelUpload(3, 50.MB());
2023-04-19 10:34:46 +00:00
}
2023-04-20 10:43:25 +00:00
[Test]
2023-04-19 10:34:46 +00:00
public void FiveNodeUploads()
{
2023-04-25 11:43:51 +00:00
ParallelUpload(5, 750.MB());
2023-04-19 10:34:46 +00:00
}
2023-04-20 10:43:25 +00:00
[Test]
2023-04-19 10:34:46 +00:00
public void TenNodeUploads()
{
2023-04-25 11:43:51 +00:00
ParallelUpload(10, 25.MB());
2023-04-20 10:43:25 +00:00
}
void ParallelUpload(int numberOfNodes, ByteSize filesize)
{
2023-04-26 13:32:27 +00:00
var group = SetupCodexNodes(numberOfNodes);
var host = SetupCodexNode();
2023-04-20 10:43:25 +00:00
2023-04-25 11:43:51 +00:00
foreach (var node in group)
2023-04-20 10:43:25 +00:00
{
2023-04-25 11:43:51 +00:00
host.ConnectToPeer(node);
2023-04-20 10:43:25 +00:00
}
2023-04-25 11:43:51 +00:00
2023-04-20 10:43:25 +00:00
var testfiles = new List<TestFile>();
2023-04-25 11:43:51 +00:00
var contentIds = new List<Task<ContentId>>();
for (int i = 0; i < group.Count(); i++)
2023-04-20 10:43:25 +00:00
{
testfiles.Add(GenerateTestFile(filesize));
2023-04-25 11:43:51 +00:00
var n = i;
contentIds.Add(Task.Run(() => { return host.UploadFile(testfiles[n]); }));
2023-04-20 10:43:25 +00:00
}
2023-04-25 11:43:51 +00:00
var downloads = new List<Task<TestFile?>>();
for (int i = 0; i < group.Count(); i++)
2023-04-20 10:43:25 +00:00
{
2023-04-25 11:43:51 +00:00
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);
2023-04-20 10:43:25 +00:00
}
2023-04-19 10:34:46 +00:00
}
}
}