Skip to content

Commit 7bf8776

Browse files
committed
Reduce risk of port clashes
Running all the tests in parallel sometimes results in port collisions, so use a wider range of random ports.
1 parent c93c385 commit 7bf8776

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Tests/Tests.MonoTorrent.Client/MonoTorrent.Client/MultiProtocolHttpTrackerTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,15 @@ public async Task AnnounceIPv6_OnlyIPv6Active ()
259259
CollectionAssert.Contains (peersFromAnnounce, peer);
260260
}
261261

262-
int preferredPort = 54399;
263262
ITrackerListener AddListener (AddressFamily addressFamily)
264263
{
265264
HttpTrackerListener listener = null;
266265

267266
// Try to work around port-in-use issues in CI. Urgh. This is awful :P
268-
for (int i = 0; i < 10; i++) {
269-
preferredPort++;
267+
int preferredPort = -1;
268+
var portGenerator = new Random ();
269+
for (int i = 0; i < 100; i++) {
270+
preferredPort = portGenerator.Next (10000, 50000);
270271

271272
if (addressFamily == AddressFamily.InterNetwork) {
272273
listener = new HttpTrackerListener (new IPEndPoint (IPAddress.Loopback, preferredPort));
@@ -301,9 +302,9 @@ ITrackerListener AddListener (AddressFamily addressFamily)
301302

302303
var uri = new Uri ($"http://localhost:{preferredPort}/announce");
303304
if (addressFamily == AddressFamily.InterNetwork)
304-
ConnectionIPv4 = new HttpTrackerConnection (uri, Factories.Default.CreateHttpClient, AddressFamily.InterNetwork);
305+
ConnectionIPv4 = new HttpTrackerConnection (uri, Factories.Default.CreateHttpClient, addressFamily);
305306
if (addressFamily == AddressFamily.InterNetworkV6)
306-
ConnectionIPv6 = new HttpTrackerConnection (uri, Factories.Default.CreateHttpClient, AddressFamily.InterNetworkV6);
307+
ConnectionIPv6 = new HttpTrackerConnection (uri, Factories.Default.CreateHttpClient, addressFamily);
307308

308309
return listener;
309310
}

0 commit comments

Comments
 (0)