mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-05-07 18:09:36 +00:00
* ci(docker): build dist-tests images * Update to .net 10, kubernetes client 18.0.13 Kubernetes client 18.0.13 is compatible with Kubernetes 1.34.x. The Kubernetes version is selected automatically by kubeadm in docker desktop (v1.34.1). See https://github.com/kubernetes-client/csharp#version-compatibility for a compatibility table. * Updates to support Kubernetes upgrade * bump openapi.yaml to match openapi.yaml in the logos-storage-nim docker image * bump doc to .net 10 * bump docker to .net 10 * Build image with latest tag always Always build an image with a latest tag (as well as a sha commit hash) when there's a push to master * docker image tag as "latest" only when pushing to master * Update docker image to install doctl * Remove doctl install kubeconfig is now created and uses a plain bearer token instead of using doctl as a credential mgr * Rename and remove all instances of Codex * Further remove CodexNetDeployer as it is no longer needed --------- Co-authored-by: Adam Uhlíř <adam@uhlir.dev>
198 lines
6.8 KiB
C#
198 lines
6.8 KiB
C#
using LogosStorageClient;
|
|
using StoragePlugin;
|
|
using LogosStorageTests;
|
|
using FileUtils;
|
|
using NUnit.Framework;
|
|
using Utils;
|
|
|
|
namespace LogosStorageReleaseTests.DataTests
|
|
{
|
|
namespace SwarmTests
|
|
{
|
|
[TestFixture(2, 10)]
|
|
[TestFixture(5, 20)]
|
|
[TestFixture(10, 20)]
|
|
public class SwarmTests : AutoBootstrapDistTest
|
|
{
|
|
private readonly int numberOfNodes;
|
|
private readonly int filesizeMb;
|
|
private IStorageNodeGroup nodes = null!;
|
|
|
|
public SwarmTests(int numberOfNodes, int filesizeMb)
|
|
{
|
|
this.numberOfNodes = numberOfNodes;
|
|
this.filesizeMb = filesizeMb;
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
ITransferSpeeds speeds = new TransferSpeeds();
|
|
foreach (var n in nodes)
|
|
{
|
|
speeds = speeds.Combine(n.TransferSpeeds);
|
|
}
|
|
Log($"Average upload speed: {speeds.GetUploadSpeed()}");
|
|
Log($"Average download speed: {speeds.GetDownloadSpeed()}");
|
|
}
|
|
|
|
[Test]
|
|
public void Stream()
|
|
{
|
|
var filesize = filesizeMb.MB();
|
|
nodes = StartLogosStorage(numberOfNodes);
|
|
var files = nodes.Select(n => UploadUniqueFilePerNode(n, filesize)).ToArray();
|
|
|
|
var tasks = ParallelDownloadEachFile(files);
|
|
Task.WaitAll(tasks);
|
|
|
|
AssertAllFilesDownloadedCorrectly(files);
|
|
}
|
|
|
|
[Test]
|
|
public void Streamless()
|
|
{
|
|
var filesize = filesizeMb.MB();
|
|
nodes = StartLogosStorage(numberOfNodes);
|
|
var files = nodes.Select(n => UploadUniqueFilePerNode(n, filesize)).ToArray();
|
|
|
|
var tasks = ParallelStreamlessDownloadEachFile(files);
|
|
Task.WaitAll(tasks);
|
|
|
|
AssertAllFilesStreamlesslyDownloadedCorrectly(files);
|
|
}
|
|
|
|
private SwarmTestNetworkFile UploadUniqueFilePerNode(IStorageNode node, ByteSize fileSize)
|
|
{
|
|
var file = GenerateTestFile(fileSize);
|
|
var cid = node.UploadFile(file);
|
|
return new SwarmTestNetworkFile(node, fileSize, file, cid);
|
|
}
|
|
|
|
private Task[] ParallelDownloadEachFile(SwarmTestNetworkFile[] files)
|
|
{
|
|
var tasks = new List<Task>();
|
|
|
|
foreach (var node in nodes)
|
|
{
|
|
tasks.Add(StartDownload(node, files));
|
|
}
|
|
|
|
return tasks.ToArray();
|
|
}
|
|
|
|
private Task[] ParallelStreamlessDownloadEachFile(SwarmTestNetworkFile[] files)
|
|
{
|
|
var tasks = new List<Task>();
|
|
|
|
foreach (var node in nodes)
|
|
{
|
|
tasks.Add(StartStreamlessDownload(node, files));
|
|
}
|
|
|
|
return tasks.ToArray();
|
|
}
|
|
|
|
private Task StartDownload(IStorageNode node, SwarmTestNetworkFile[] files)
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
var remaining = files.ToList();
|
|
|
|
while (remaining.Count > 0)
|
|
{
|
|
var file = remaining.PickOneRandom();
|
|
try
|
|
{
|
|
var dl = node.DownloadContent(file.Cid, TimeSpan.FromMinutes(30));
|
|
lock (file.Lock)
|
|
{
|
|
file.Downloaded.Add(dl);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
file.Error = ex;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private Task StartStreamlessDownload(IStorageNode node, SwarmTestNetworkFile[] files)
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
var remaining = files.ToList();
|
|
|
|
while (remaining.Count > 0)
|
|
{
|
|
var file = remaining.PickOneRandom();
|
|
if (file.Uploader.GetName() != node.GetName())
|
|
{
|
|
try
|
|
{
|
|
var startSpace = node.Space();
|
|
node.DownloadStreamlessWait(file.Cid, file.OriginalSize);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
file.Error = ex;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void AssertAllFilesDownloadedCorrectly(SwarmTestNetworkFile[] files)
|
|
{
|
|
foreach (var file in files)
|
|
{
|
|
if (file.Error != null) throw file.Error;
|
|
lock (file.Lock)
|
|
{
|
|
foreach (var dl in file.Downloaded)
|
|
{
|
|
file.Original.AssertIsEqual(dl);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void AssertAllFilesStreamlesslyDownloadedCorrectly(SwarmTestNetworkFile[] files)
|
|
{
|
|
var totalFilesSpace = 0.Bytes();
|
|
foreach (var file in files)
|
|
{
|
|
if (file.Error != null) throw file.Error;
|
|
totalFilesSpace = new ByteSize(totalFilesSpace.SizeInBytes + file.Original.GetFilesize().SizeInBytes);
|
|
}
|
|
|
|
foreach (var node in nodes)
|
|
{
|
|
var currentSpace = node.Space();
|
|
Assert.That(currentSpace.QuotaUsedBytes, Is.GreaterThanOrEqualTo(totalFilesSpace.SizeInBytes));
|
|
}
|
|
}
|
|
|
|
private class SwarmTestNetworkFile
|
|
{
|
|
public SwarmTestNetworkFile(IStorageNode uploader, ByteSize originalSize, TrackedFile original, ContentId cid)
|
|
{
|
|
Uploader = uploader;
|
|
OriginalSize = originalSize;
|
|
Original = original;
|
|
Cid = cid;
|
|
}
|
|
|
|
public IStorageNode Uploader { get; }
|
|
public ByteSize OriginalSize { get; }
|
|
public TrackedFile Original { get; }
|
|
public ContentId Cid { get; }
|
|
public object Lock { get; } = new object();
|
|
public List<TrackedFile?> Downloaded { get; } = new List<TrackedFile?>();
|
|
public Exception? Error { get; set; } = null;
|
|
}
|
|
}
|
|
}
|
|
}
|