Disables assert on contract config values check

This commit is contained in:
Ben 2025-09-01 10:35:40 +02:00
parent 365e78f050
commit c16397ae47
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
3 changed files with 173 additions and 136 deletions

View File

@ -6,6 +6,7 @@ namespace CodexClient
{
BytesPerSecond? GetUploadSpeed();
BytesPerSecond? GetDownloadSpeed();
ITransferSpeeds Combine(ITransferSpeeds? other);
}
public class TransferSpeeds : ITransferSpeeds
@ -35,6 +36,18 @@ namespace CodexClient
return downloads.Average();
}
public ITransferSpeeds Combine(ITransferSpeeds? other)
{
if (other == null) return this;
var o = (TransferSpeeds)other;
var result = new TransferSpeeds();
result.uploads.AddRange(uploads);
result.uploads.AddRange(o.uploads);
result.downloads.AddRange(downloads);
result.downloads.AddRange(o.downloads);
return result;
}
private static BytesPerSecond Convert(ByteSize size, TimeSpan duration)
{
double bytes = size.SizeInBytes;

View File

@ -105,7 +105,15 @@ namespace CodexContractsPlugin
{
if (Convert.ToInt32(value) != expected)
{
throw new Exception($"Config value '{name}' should be deployed as '{expected}' but was '{value}'");
// Merge todo: https://github.com/codex-storage/nim-codex/pull/1303
// Once this is merged, the contract config values are settable via env-vars.
// This plugin is already updated to set the config vars to values compatible with a
// 1-second block frequency. AND it will read back the config and assert it is deployed correctly.
// This is waiting for that merge.
// Replace log with assert WHEN MERGED:
// throw new Exception($"Config value '{name}' should be deployed as '{expected}' but was '{value}'");
Log($"MERGE TODO. Config value '{name}' should be deployed as '{expected}' but was '{value}'");
}
}

View File

@ -7,6 +7,8 @@ using Utils;
namespace CodexReleaseTests.DataTests
{
namespace SwarmTests
{
[TestFixture(2, 10)]
[TestFixture(5, 20)]
[TestFixture(10, 20)]
@ -14,6 +16,7 @@ namespace CodexReleaseTests.DataTests
{
private readonly int numberOfNodes;
private readonly int filesizeMb;
private ICodexNodeGroup nodes = null!;
public SwarmTests(int numberOfNodes, int filesizeMb)
{
@ -21,30 +24,42 @@ namespace CodexReleaseTests.DataTests
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 Swarm()
public void Stream()
{
var filesize = filesizeMb.MB();
var nodes = StartCodex(numberOfNodes);
nodes = StartCodex(numberOfNodes);
var files = nodes.Select(n => UploadUniqueFilePerNode(n, filesize)).ToArray();
var tasks = ParallelDownloadEachFile(nodes, files);
var tasks = ParallelDownloadEachFile(files);
Task.WaitAll(tasks);
AssertAllFilesDownloadedCorrectly(files);
}
[Test]
public void StreamlessSwarm()
public void Streamless()
{
var filesize = filesizeMb.MB();
var nodes = StartCodex(numberOfNodes);
nodes = StartCodex(numberOfNodes);
var files = nodes.Select(n => UploadUniqueFilePerNode(n, filesize)).ToArray();
var tasks = ParallelStreamlessDownloadEachFile(nodes, files);
var tasks = ParallelStreamlessDownloadEachFile(files);
Task.WaitAll(tasks);
AssertAllFilesStreamlesslyDownloadedCorrectly(nodes, files);
AssertAllFilesStreamlesslyDownloadedCorrectly(files);
}
private SwarmTestNetworkFile UploadUniqueFilePerNode(ICodexNode node, ByteSize fileSize)
@ -54,7 +69,7 @@ namespace CodexReleaseTests.DataTests
return new SwarmTestNetworkFile(node, fileSize, file, cid);
}
private Task[] ParallelDownloadEachFile(ICodexNodeGroup nodes, SwarmTestNetworkFile[] files)
private Task[] ParallelDownloadEachFile(SwarmTestNetworkFile[] files)
{
var tasks = new List<Task>();
@ -66,7 +81,7 @@ namespace CodexReleaseTests.DataTests
return tasks.ToArray();
}
private Task[] ParallelStreamlessDownloadEachFile(ICodexNodeGroup nodes, SwarmTestNetworkFile[] files)
private Task[] ParallelStreamlessDownloadEachFile(SwarmTestNetworkFile[] files)
{
var tasks = new List<Task>();
@ -143,7 +158,7 @@ namespace CodexReleaseTests.DataTests
}
}
private void AssertAllFilesStreamlesslyDownloadedCorrectly(ICodexNodeGroup nodes, SwarmTestNetworkFile[] files)
private void AssertAllFilesStreamlesslyDownloadedCorrectly(SwarmTestNetworkFile[] files)
{
var totalFilesSpace = 0.Bytes();
foreach (var file in files)
@ -178,4 +193,5 @@ namespace CodexReleaseTests.DataTests
public Exception? Error { get; set; } = null;
}
}
}
}