2024-06-18 09:04:04 +00:00
|
|
|
|
using CodexPlugin;
|
|
|
|
|
using NUnit.Framework;
|
2023-09-12 13:43:30 +00:00
|
|
|
|
using Utils;
|
|
|
|
|
|
2023-10-09 14:59:52 +00:00
|
|
|
|
namespace CodexTests.BasicTests
|
2023-09-12 13:43:30 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class ThreeClientTest : AutoBootstrapDistTest
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void ThreeClient()
|
|
|
|
|
{
|
2024-05-09 07:32:48 +00:00
|
|
|
|
var primary = StartCodex();
|
|
|
|
|
var secondary = StartCodex();
|
2023-09-12 13:43:30 +00:00
|
|
|
|
|
|
|
|
|
var testFile = GenerateTestFile(10.MB());
|
|
|
|
|
|
|
|
|
|
var contentId = primary.UploadFile(testFile);
|
|
|
|
|
|
|
|
|
|
var downloadedFile = secondary.DownloadContent(contentId);
|
|
|
|
|
|
|
|
|
|
testFile.AssertIsEqual(downloadedFile);
|
|
|
|
|
}
|
2024-06-18 09:04:04 +00:00
|
|
|
|
|
2024-08-06 13:56:42 +00:00
|
|
|
|
[Test]
|
|
|
|
|
[CreateTranscript(nameof(SwarmTest))]
|
|
|
|
|
public void SwarmTest()
|
|
|
|
|
{
|
|
|
|
|
var uploader = StartCodex(s => s.WithName("uploader"));
|
|
|
|
|
var downloaders = StartCodex(5, s => s.WithName("downloader"));
|
|
|
|
|
|
|
|
|
|
var file = GenerateTestFile(100.MB());
|
|
|
|
|
var cid = uploader.UploadFile(file);
|
|
|
|
|
|
|
|
|
|
var result = Parallel.ForEach(downloaders, d =>
|
|
|
|
|
{
|
|
|
|
|
d.DownloadContent(cid);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Assert.That(result.IsCompleted);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 09:04:04 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void DownloadingUnknownCidDoesNotCauseCrash()
|
|
|
|
|
{
|
|
|
|
|
var node = StartCodex(2).First();
|
|
|
|
|
|
|
|
|
|
var unknownCid = new ContentId("zDvZRwzkzHsok3Z8yMoiXE9EDBFwgr8WygB8s4ddcLzzSwwXAxLZ");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
node.DownloadContent(unknownCid);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
if (!ex.Message.StartsWith("Retry 'DownloadFile' timed out"))
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that the node stays alive for at least another 5 minutes.
|
|
|
|
|
var start = DateTime.UtcNow;
|
|
|
|
|
while ((DateTime.UtcNow - start) < TimeSpan.FromMinutes(5))
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
var info = node.GetDebugInfo();
|
|
|
|
|
Assert.That(!string.IsNullOrEmpty(info.Id));
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-12 13:43:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|