2023-07-18 14:07:52 +00:00
|
|
|
|
using static DistTestCore.Helpers.FullConnectivityHelper;
|
2023-06-06 12:36:37 +00:00
|
|
|
|
|
|
|
|
|
namespace DistTestCore.Helpers
|
2023-05-29 07:13:38 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
public class PeerDownloadTestHelpers : IFullConnectivityImplementation
|
2023-05-29 07:13:38 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
private readonly FullConnectivityHelper helper;
|
2023-05-29 07:13:38 +00:00
|
|
|
|
private readonly DistTest test;
|
2023-07-18 14:07:52 +00:00
|
|
|
|
private ByteSize testFileSize;
|
2023-05-29 07:13:38 +00:00
|
|
|
|
|
|
|
|
|
public PeerDownloadTestHelpers(DistTest test)
|
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
helper = new FullConnectivityHelper(test, this);
|
|
|
|
|
testFileSize = 1.MB();
|
2023-05-29 07:13:38 +00:00
|
|
|
|
this.test = test;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AssertFullDownloadInterconnectivity(IEnumerable<IOnlineCodexNode> nodes, ByteSize testFileSize)
|
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
this.testFileSize = testFileSize;
|
|
|
|
|
helper.AssertFullyConnected(nodes);
|
2023-06-06 12:36:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-18 14:07:52 +00:00
|
|
|
|
public string Description()
|
2023-06-06 12:36:37 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
return "Download Connectivity";
|
|
|
|
|
}
|
2023-06-06 12:36:37 +00:00
|
|
|
|
|
2023-07-18 14:07:52 +00:00
|
|
|
|
public string ValidateEntry(Entry entry, Entry[] allEntries)
|
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
2023-05-29 07:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-18 14:07:52 +00:00
|
|
|
|
public PeerConnectionState Check(Entry from, Entry to)
|
2023-05-29 07:13:38 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
var expectedFile = GenerateTestFile(from.Node, to.Node);
|
2023-05-29 07:13:38 +00:00
|
|
|
|
|
2023-07-18 14:07:52 +00:00
|
|
|
|
var contentId = from.Node.UploadFile(expectedFile);
|
2023-05-29 07:13:38 +00:00
|
|
|
|
|
2023-07-18 14:07:52 +00:00
|
|
|
|
try
|
2023-05-29 07:13:38 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
var downloadedFile = to.Node.DownloadContent(contentId, expectedFile.Label + "_downloaded");
|
2023-05-29 07:13:38 +00:00
|
|
|
|
expectedFile.AssertIsEqual(downloadedFile);
|
2023-07-18 14:07:52 +00:00
|
|
|
|
return PeerConnectionState.Connection;
|
2023-05-29 07:13:38 +00:00
|
|
|
|
}
|
2023-07-18 14:07:52 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Should an exception occur during the download or file-content assertion,
|
|
|
|
|
// We consider that as no-connection for the purpose of this test.
|
|
|
|
|
return PeerConnectionState.NoConnection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Should an exception occur during upload, then this try is inconclusive and we try again next loop.
|
2023-05-29 07:13:38 +00:00
|
|
|
|
}
|
2023-06-04 06:59:51 +00:00
|
|
|
|
|
2023-07-18 14:07:52 +00:00
|
|
|
|
private TestFile GenerateTestFile(IOnlineCodexNode uploader, IOnlineCodexNode downloader)
|
2023-06-04 06:59:51 +00:00
|
|
|
|
{
|
|
|
|
|
var up = uploader.GetName().Replace("<", "").Replace(">", "");
|
|
|
|
|
var down = downloader.GetName().Replace("<", "").Replace(">", "");
|
2023-07-18 14:07:52 +00:00
|
|
|
|
var label = $"~from:{up}-to:{down}~";
|
2023-06-04 06:59:51 +00:00
|
|
|
|
return test.GenerateTestFile(testFileSize, label);
|
|
|
|
|
}
|
2023-05-29 07:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|