Skip to content

Commit e19311c

Browse files
committed
Downloads 1 file per node at a time in swarm test.
1 parent b8476f6 commit e19311c

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

Tests/CodexReleaseTests/DataTests/SwarmTest.cs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
using CodexTests;
33
using FileUtils;
44
using NUnit.Framework;
5-
using System;
6-
using System.Collections.Generic;
7-
using System.Linq;
8-
using System.Text;
9-
using System.Threading.Tasks;
105
using Utils;
116

127
namespace CodexReleaseTests.DataTests
@@ -42,26 +37,33 @@ private Task[] ParallelDownloadEachFile(ICodexNodeGroup nodes, SwarmTestNetworkF
4237

4338
foreach (var node in nodes)
4439
{
45-
foreach (var file in files)
46-
{
47-
tasks.Add(StartDownload(node, file));
48-
}
40+
tasks.Add(StartDownload(node, files));
4941
}
5042

5143
return tasks.ToArray();
5244
}
5345

54-
private Task StartDownload(ICodexNode node, SwarmTestNetworkFile file)
46+
private Task StartDownload(ICodexNode node, SwarmTestNetworkFile[] files)
5547
{
5648
return Task.Run(() =>
5749
{
58-
try
59-
{
60-
file.Downloaded = node.DownloadContent(file.Cid);
61-
}
62-
catch (Exception ex)
50+
var remaining = files.ToList();
51+
52+
while (remaining.Count > 0)
6353
{
64-
file.Error = ex;
54+
var file = remaining.PickOneRandom();
55+
try
56+
{
57+
var dl = node.DownloadContent(file.Cid);
58+
lock (file.Lock)
59+
{
60+
file.Downloaded.Add(dl);
61+
}
62+
}
63+
catch (Exception ex)
64+
{
65+
file.Error = ex;
66+
}
6567
}
6668
});
6769
}
@@ -71,7 +73,13 @@ private void AssertAllFilesDownloadedCorrectly(SwarmTestNetworkFile[] files)
7173
foreach (var file in files)
7274
{
7375
if (file.Error != null) throw file.Error;
74-
file.Original.AssertIsEqual(file.Downloaded);
76+
lock (file.Lock)
77+
{
78+
foreach (var dl in file.Downloaded)
79+
{
80+
file.Original.AssertIsEqual(dl);
81+
}
82+
}
7583
}
7684
}
7785

@@ -85,7 +93,8 @@ public SwarmTestNetworkFile(TrackedFile original, ContentId cid)
8593

8694
public TrackedFile Original { get; }
8795
public ContentId Cid { get; }
88-
public TrackedFile? Downloaded { get; set; }
96+
public object Lock { get; } = new object();
97+
public List<TrackedFile?> Downloaded { get; } = new List<TrackedFile?>();
8998
public Exception? Error { get; set; } = null;
9099
}
91100
}

0 commit comments

Comments
 (0)