streamelss and manifestonly tests

This commit is contained in:
Ben 2024-11-21 11:21:41 +01:00
parent 704847001d
commit f1f3b0f173
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
3 changed files with 76 additions and 0 deletions

View File

@ -37,6 +37,8 @@ namespace CodexPlugin
/// </summary>
void DeleteRepoFolder();
void Stop(bool waitTillStopped);
void DownloadStreamless(ContentId cid);
Manifest DownloadManifestOnly(ContentId cid);
}
public class CodexNode : ICodexNode

View File

@ -0,0 +1,31 @@
using CodexTests;
using NUnit.Framework;
using Utils;
namespace CodexReleaseTests.DataTests
{
[TestFixture]
public class ManifestOnlyDownloadTest : CodexDistTest
{
[Test]
public void StreamlessTest()
{
var uploader = StartCodex();
var downloader = StartCodex(s => s.WithBootstrapNode(uploader));
var file = GenerateTestFile(2.GB());
var size = Convert.ToInt64(file.GetFilesize());
var cid = uploader.UploadFile(file);
var startSpace = downloader.Space();
var manifest = downloader.DownloadManifestOnly(cid);
Thread.Sleep(1000);
var spaceDiff = startSpace.FreeBytes - downloader.Space().FreeBytes;
Assert.That(spaceDiff, Is.LessThan(64.KB().SizeInBytes));
Assert.That(manifest.OriginalBytes.SizeInBytes, Is.EqualTo(file.GetFilesize().SizeInBytes));
}
}
}

View File

@ -0,0 +1,43 @@
using CodexTests;
using NUnit.Framework;
using Utils;
namespace CodexReleaseTests.DataTests
{
[TestFixture]
public class StreamlessDownloadTest : CodexDistTest
{
[Test]
public void StreamlessTest()
{
var uploader = StartCodex();
var downloader = StartCodex(s => s.WithBootstrapNode(uploader));
var file = GenerateTestFile(10.MB());
var size = Convert.ToInt64(file.GetFilesize());
var cid = uploader.UploadFile(file);
var startSpace = downloader.Space();
var start = DateTime.UtcNow;
downloader.DownloadStreamless(cid);
// TODO: We have no way to inspect the status or progress of the download.
// We use local space information to estimate.
var retry = new Retry("Checking local space",
maxTimeout: TimeSpan.FromMinutes(2),
sleepAfterFail: TimeSpan.FromSeconds(3),
onFail: f => { });
retry.Run(() =>
{
var space = downloader.Space();
Assert.That(space.FreeBytes, Is.LessThanOrEqualTo(startSpace.FreeBytes - size));
});
// Stop the uploader node and verify that the downloader has the data.
uploader.Stop(waitTillStopped: true);
var downloaded = downloader.DownloadContent(cid);
file.AssertIsEqual(downloaded);
}
}
}