2024-04-13 13:27:47 +00:00
|
|
|
using CodexPlugin;
|
2024-04-13 14:33:21 +00:00
|
|
|
using DistTestCore;
|
2024-04-15 06:12:57 +00:00
|
|
|
using FileUtils;
|
2024-04-13 13:27:47 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using Utils;
|
|
|
|
|
|
|
|
namespace CodexTests.ScalabilityTests;
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
public class ScalabilityTests : CodexDistTest
|
|
|
|
{
|
2024-04-15 06:12:57 +00:00
|
|
|
/// <summary>
|
|
|
|
/// We upload a file to node A, then download it with B.
|
|
|
|
/// Then we stop node A, and download again with node C.
|
|
|
|
/// </summary>
|
2024-04-13 13:27:47 +00:00
|
|
|
[Test]
|
|
|
|
[Combinatorial]
|
2024-04-13 14:33:21 +00:00
|
|
|
[UseLongTimeouts]
|
2024-04-15 05:36:12 +00:00
|
|
|
[DontDownloadLogs]
|
2024-04-13 13:27:47 +00:00
|
|
|
public void ShouldMaintainFileInNetwork(
|
2024-04-14 08:43:06 +00:00
|
|
|
[Values(10, 40, 80, 100)] int numberOfNodes,
|
2024-05-01 11:51:46 +00:00
|
|
|
[Values(100, 1000, 5000, 10000)] int fileSizeInMb
|
2024-04-13 13:27:47 +00:00
|
|
|
)
|
|
|
|
{
|
2024-04-15 05:57:13 +00:00
|
|
|
var logLevel = CodexLogLevel.Info;
|
|
|
|
|
|
|
|
var bootstrap = AddCodex(s => s.WithLogLevel(logLevel));
|
|
|
|
var nodes = AddCodex(numberOfNodes - 1, s => s
|
|
|
|
.WithBootstrapNode(bootstrap)
|
|
|
|
.WithLogLevel(logLevel)
|
|
|
|
.WithStorageQuota((fileSizeInMb + 50).MB())
|
|
|
|
).ToList();
|
2024-04-13 13:27:47 +00:00
|
|
|
|
|
|
|
var uploader = nodes.PickOneRandom();
|
|
|
|
var downloader = nodes.PickOneRandom();
|
|
|
|
|
|
|
|
var testFile = GenerateTestFile(fileSizeInMb.MB());
|
|
|
|
var contentId = uploader.UploadFile(testFile);
|
|
|
|
var downloadedFile = downloader.DownloadContent(contentId);
|
|
|
|
|
|
|
|
downloadedFile!.AssertIsEqual(testFile);
|
|
|
|
|
|
|
|
uploader.Stop(true);
|
|
|
|
|
|
|
|
var otherDownloader = nodes.PickOneRandom();
|
|
|
|
downloadedFile = otherDownloader.DownloadContent(contentId);
|
|
|
|
|
|
|
|
downloadedFile!.AssertIsEqual(testFile);
|
|
|
|
}
|
2024-04-15 06:12:57 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// We upload a file to each node, to put a more wide-spread load on the network.
|
|
|
|
/// Then we run the same test as ShouldMaintainFileInNetwork.
|
|
|
|
/// </summary>
|
2024-05-07 07:49:00 +00:00
|
|
|
[Ignore("Fix ShouldMaintainFileInNetwork for all values first")]
|
2024-04-15 06:12:57 +00:00
|
|
|
[Test]
|
|
|
|
[Combinatorial]
|
|
|
|
[UseLongTimeouts]
|
|
|
|
[DontDownloadLogs]
|
|
|
|
public void EveryoneGetsAFile(
|
|
|
|
[Values(10, 40, 80, 100)] int numberOfNodes,
|
2024-05-01 11:51:46 +00:00
|
|
|
[Values(100, 1000, 5000, 10000)] int fileSizeInMb
|
2024-04-15 06:12:57 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
var logLevel = CodexLogLevel.Info;
|
|
|
|
|
|
|
|
var bootstrap = AddCodex(s => s.WithLogLevel(logLevel));
|
|
|
|
var nodes = AddCodex(numberOfNodes - 1, s => s
|
|
|
|
.WithBootstrapNode(bootstrap)
|
|
|
|
.WithLogLevel(logLevel)
|
|
|
|
.WithStorageQuota((fileSizeInMb + 50).MB())
|
|
|
|
).ToList();
|
|
|
|
|
|
|
|
var pairTasks = nodes.Select(n =>
|
|
|
|
{
|
|
|
|
return Task.Run(() =>
|
|
|
|
{
|
|
|
|
var file = GenerateTestFile(fileSizeInMb.MB());
|
|
|
|
var cid = n.UploadFile(file);
|
|
|
|
return new NodeFilePair(n, file, cid);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var pairs = pairTasks.Select(t => Time.Wait(t)).ToList();
|
|
|
|
|
|
|
|
RunDoubleDownloadTest(
|
|
|
|
pairs.PickOneRandom(),
|
|
|
|
pairs.PickOneRandom(),
|
|
|
|
pairs.PickOneRandom()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RunDoubleDownloadTest(NodeFilePair source, NodeFilePair dl1, NodeFilePair dl2)
|
|
|
|
{
|
|
|
|
var expectedFile = source.File;
|
|
|
|
var cid = source.Cid;
|
|
|
|
|
|
|
|
var file1 = dl1.Node.DownloadContent(cid);
|
|
|
|
file1!.AssertIsEqual(expectedFile);
|
|
|
|
|
|
|
|
source.Node.Stop(true);
|
|
|
|
|
|
|
|
var file2 = dl2.Node.DownloadContent(cid);
|
|
|
|
file2!.AssertIsEqual(expectedFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class NodeFilePair
|
|
|
|
{
|
|
|
|
public NodeFilePair(ICodexNode node, TrackedFile file, ContentId cid)
|
|
|
|
{
|
|
|
|
Node = node;
|
|
|
|
File = file;
|
|
|
|
Cid = cid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ICodexNode Node { get; }
|
|
|
|
public TrackedFile File { get; }
|
|
|
|
public ContentId Cid { get; }
|
|
|
|
}
|
2024-04-15 05:57:13 +00:00
|
|
|
}
|