cs-codex-dist-tests/DistTestCore/Helpers/PeerDownloadTestHelpers.cs

65 lines
2.2 KiB
C#
Raw Normal View History

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-07-18 14:07:52 +00:00
public class PeerDownloadTestHelpers : IFullConnectivityImplementation
{
2023-07-18 14:07:52 +00:00
private readonly FullConnectivityHelper helper;
private readonly DistTest test;
2023-07-18 14:07:52 +00:00
private ByteSize testFileSize;
public PeerDownloadTestHelpers(DistTest test)
{
2023-07-18 14:07:52 +00:00
helper = new FullConnectivityHelper(test, this);
testFileSize = 1.MB();
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-07-18 14:07:52 +00:00
public PeerConnectionState Check(Entry from, Entry to)
{
2023-07-18 14:07:52 +00:00
var expectedFile = GenerateTestFile(from.Node, to.Node);
2023-07-18 14:07:52 +00:00
var contentId = from.Node.UploadFile(expectedFile);
2023-07-18 14:07:52 +00:00
try
{
2023-07-18 14:07:52 +00:00
var downloadedFile = to.Node.DownloadContent(contentId, expectedFile.Label + "_downloaded");
expectedFile.AssertIsEqual(downloadedFile);
2023-07-18 14:07:52 +00:00
return PeerConnectionState.Connection;
}
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-07-18 14:07:52 +00:00
private TestFile GenerateTestFile(IOnlineCodexNode uploader, IOnlineCodexNode downloader)
{
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}~";
return test.GenerateTestFile(testFileSize, label);
}
}
}