cs-codex-dist-tests/Tests/CodexLongTests/BasicTests/DownloadTests.cs

54 lines
1.5 KiB
C#
Raw Normal View History

2024-05-07 08:15:02 +00:00
using CodexPlugin;
using CodexTests;
2023-04-26 12:59:26 +00:00
using DistTestCore;
using FileUtils;
2023-04-26 12:59:26 +00:00
using NUnit.Framework;
2023-09-08 08:21:40 +00:00
using Utils;
2023-09-20 08:59:52 +00:00
namespace CodexLongTests.BasicTests
2023-04-26 12:59:26 +00:00
{
[TestFixture]
2024-05-07 08:15:02 +00:00
public class DownloadTests : AutoBootstrapDistTest
2023-04-26 12:59:26 +00:00
{
2024-05-07 08:15:02 +00:00
[Test]
[Combinatorial]
[UseLongTimeouts]
2024-05-07 08:15:02 +00:00
public void ParallelDownload(
[Values(1, 3, 5)] int numberOfFiles,
[Values(10, 50, 100)] int filesizeMb)
2023-04-26 12:59:26 +00:00
{
2023-09-20 08:59:52 +00:00
var host = AddCodex();
2024-05-07 08:15:02 +00:00
var client = AddCodex();
2023-04-26 12:59:26 +00:00
2024-05-07 08:15:02 +00:00
var testfiles = new List<TrackedFile>();
var contentIds = new List<ContentId>();
var downloadedFiles = new List<TrackedFile?>();
for (int i = 0; i < numberOfFiles; i++)
2023-04-26 12:59:26 +00:00
{
2024-05-07 08:15:02 +00:00
testfiles.Add(GenerateTestFile(filesizeMb.MB()));
contentIds.Add(new ContentId());
downloadedFiles.Add(null);
2023-04-26 12:59:26 +00:00
}
2024-05-07 08:15:02 +00:00
for (int i = 0; i < numberOfFiles; i++)
{
contentIds[i] = host.UploadFile(testfiles[i]);
}
2023-06-01 10:27:54 +00:00
2024-05-07 08:15:02 +00:00
var downloadTasks = new List<Task>();
for (int i = 0; i < numberOfFiles; i++)
2023-04-26 12:59:26 +00:00
{
2024-05-07 08:15:02 +00:00
downloadTasks.Add(Task.Run(() => { downloadedFiles[i] = client.DownloadContent(contentIds[i]); }));
2023-04-26 12:59:26 +00:00
}
2024-05-07 08:15:02 +00:00
Task.WaitAll(downloadTasks.ToArray());
for (int i = 0; i < numberOfFiles; i++)
2023-04-26 12:59:26 +00:00
{
2024-05-07 08:15:02 +00:00
testfiles[i].AssertIsEqual(downloadedFiles[i]);
2023-04-26 12:59:26 +00:00
}
}
}
}