2023-05-29 07:13:38 +00:00
|
|
|
|
namespace DistTestCore.Helpers
|
|
|
|
|
{
|
|
|
|
|
public class PeerDownloadTestHelpers
|
|
|
|
|
{
|
|
|
|
|
private readonly DistTest test;
|
|
|
|
|
|
|
|
|
|
public PeerDownloadTestHelpers(DistTest test)
|
|
|
|
|
{
|
|
|
|
|
this.test = test;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AssertFullDownloadInterconnectivity(IEnumerable<IOnlineCodexNode> nodes)
|
|
|
|
|
{
|
|
|
|
|
AssertFullDownloadInterconnectivity(nodes, 1.MB());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AssertFullDownloadInterconnectivity(IEnumerable<IOnlineCodexNode> nodes, ByteSize testFileSize)
|
|
|
|
|
{
|
2023-05-31 11:15:41 +00:00
|
|
|
|
test.Log($"Asserting full download interconnectivity for nodes: '{string.Join(",", nodes.Select(n => n.GetName()))}'...");
|
2023-05-29 07:13:38 +00:00
|
|
|
|
foreach (var node in nodes)
|
|
|
|
|
{
|
|
|
|
|
var uploader = node;
|
|
|
|
|
var downloaders = nodes.Where(n => n != uploader).ToArray();
|
|
|
|
|
|
|
|
|
|
test.ScopedTestFiles(() =>
|
|
|
|
|
{
|
2023-05-29 07:27:25 +00:00
|
|
|
|
PerformTest(uploader, downloaders, testFileSize);
|
2023-05-29 07:13:38 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2023-05-29 07:25:03 +00:00
|
|
|
|
|
2023-05-31 11:15:41 +00:00
|
|
|
|
test.Log($"Success! Full download interconnectivity for nodes: {string.Join(",", nodes.Select(n => n.GetName()))}");
|
2023-05-29 07:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 07:27:25 +00:00
|
|
|
|
private void PerformTest(IOnlineCodexNode uploader, IOnlineCodexNode[] downloaders, ByteSize testFileSize)
|
2023-05-29 07:13:38 +00:00
|
|
|
|
{
|
2023-06-04 06:59:51 +00:00
|
|
|
|
// Generate 1 test file per downloader.
|
|
|
|
|
var files = downloaders.Select(d => GenerateTestFile(uploader, d, testFileSize)).ToArray();
|
2023-05-29 07:13:38 +00:00
|
|
|
|
|
|
|
|
|
// Upload all the test files to the uploader.
|
|
|
|
|
var contentIds = files.Select(uploader.UploadFile).ToArray();
|
|
|
|
|
|
|
|
|
|
// Each downloader should retrieve its own test file.
|
|
|
|
|
for (var i = 0; i < downloaders.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var expectedFile = files[i];
|
2023-06-04 06:59:51 +00:00
|
|
|
|
var downloadedFile = downloaders[i].DownloadContent(contentIds[i], $"{expectedFile.Label}DOWNLOADED");
|
2023-05-29 07:13:38 +00:00
|
|
|
|
|
|
|
|
|
expectedFile.AssertIsEqual(downloadedFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-04 06:59:51 +00:00
|
|
|
|
|
|
|
|
|
private TestFile GenerateTestFile(IOnlineCodexNode uploader, IOnlineCodexNode downloader, ByteSize testFileSize)
|
|
|
|
|
{
|
|
|
|
|
var up = uploader.GetName().Replace("<", "").Replace(">", "");
|
|
|
|
|
var down = downloader.GetName().Replace("<", "").Replace(">", "");
|
|
|
|
|
var label = $"FROM{up}TO{down}";
|
|
|
|
|
return test.GenerateTestFile(testFileSize, label);
|
|
|
|
|
}
|
2023-05-29 07:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|