2
2
using CodexTests ;
3
3
using FileUtils ;
4
4
using NUnit . Framework ;
5
- using System ;
6
- using System . Collections . Generic ;
7
- using System . Linq ;
8
- using System . Text ;
9
- using System . Threading . Tasks ;
10
5
using Utils ;
11
6
12
7
namespace CodexReleaseTests . DataTests
@@ -42,26 +37,33 @@ private Task[] ParallelDownloadEachFile(ICodexNodeGroup nodes, SwarmTestNetworkF
42
37
43
38
foreach ( var node in nodes )
44
39
{
45
- foreach ( var file in files )
46
- {
47
- tasks . Add ( StartDownload ( node , file ) ) ;
48
- }
40
+ tasks . Add ( StartDownload ( node , files ) ) ;
49
41
}
50
42
51
43
return tasks . ToArray ( ) ;
52
44
}
53
45
54
- private Task StartDownload ( ICodexNode node , SwarmTestNetworkFile file )
46
+ private Task StartDownload ( ICodexNode node , SwarmTestNetworkFile [ ] files )
55
47
{
56
48
return Task . Run ( ( ) =>
57
49
{
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 )
63
53
{
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
+ }
65
67
}
66
68
} ) ;
67
69
}
@@ -71,7 +73,13 @@ private void AssertAllFilesDownloadedCorrectly(SwarmTestNetworkFile[] files)
71
73
foreach ( var file in files )
72
74
{
73
75
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
+ }
75
83
}
76
84
}
77
85
@@ -85,7 +93,8 @@ public SwarmTestNetworkFile(TrackedFile original, ContentId cid)
85
93
86
94
public TrackedFile Original { get ; }
87
95
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 ? > ( ) ;
89
98
public Exception ? Error { get ; set ; } = null ;
90
99
}
91
100
}
0 commit comments