Downloads 1 file per node at a time in swarm test.

This commit is contained in:
benbierens 2024-12-05 11:29:21 +01:00
parent b8476f697e
commit e19311cef9
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A

View File

@ -2,11 +2,6 @@
using CodexTests; using CodexTests;
using FileUtils; using FileUtils;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Utils; using Utils;
namespace CodexReleaseTests.DataTests namespace CodexReleaseTests.DataTests
@ -42,26 +37,33 @@ namespace CodexReleaseTests.DataTests
foreach (var node in nodes) foreach (var node in nodes)
{ {
foreach (var file in files) tasks.Add(StartDownload(node, files));
{
tasks.Add(StartDownload(node, file));
}
} }
return tasks.ToArray(); return tasks.ToArray();
} }
private Task StartDownload(ICodexNode node, SwarmTestNetworkFile file) private Task StartDownload(ICodexNode node, SwarmTestNetworkFile[] files)
{ {
return Task.Run(() => return Task.Run(() =>
{ {
try var remaining = files.ToList();
while (remaining.Count > 0)
{ {
file.Downloaded = node.DownloadContent(file.Cid); var file = remaining.PickOneRandom();
} try
catch (Exception ex) {
{ var dl = node.DownloadContent(file.Cid);
file.Error = ex; lock (file.Lock)
{
file.Downloaded.Add(dl);
}
}
catch (Exception ex)
{
file.Error = ex;
}
} }
}); });
} }
@ -71,7 +73,13 @@ namespace CodexReleaseTests.DataTests
foreach (var file in files) foreach (var file in files)
{ {
if (file.Error != null) throw file.Error; if (file.Error != null) throw file.Error;
file.Original.AssertIsEqual(file.Downloaded); lock (file.Lock)
{
foreach (var dl in file.Downloaded)
{
file.Original.AssertIsEqual(dl);
}
}
} }
} }
@ -85,7 +93,8 @@ namespace CodexReleaseTests.DataTests
public TrackedFile Original { get; } public TrackedFile Original { get; }
public ContentId Cid { get; } public ContentId Cid { get; }
public TrackedFile? Downloaded { get; set; } public object Lock { get; } = new object();
public List<TrackedFile?> Downloaded { get; } = new List<TrackedFile?>();
public Exception? Error { get; set; } = null; public Exception? Error { get; set; } = null;
} }
} }